Dynamic Query/Browse Question

Hi All,

I have just started (today) to try and use a Dynamic Query/Browse setup. Is a very simple browse where you pass in the buffer for the table (bh = BUFFER tablename:HANDLE), the Query and then the fields you want to display in a comma seperated list. My problem is that I have no idea on how to pass back information form what the user has selected. Maybe I am missing something but finding it hard to find this information. Please find some example code below...

Calling Program:
DEF VAR bh AS WIDGET-HANDLE NO-UNDO.

bh = BUFFER Table:HANDLE.

RUN ofs\dynbrws.w (INPUT bh,
INPUT "for each Table NO-LOCK",
INPUT "Table.Field,Table.Field2").



Definitions:

/* Parameters Definitions --- */
DEF INPUT PARAM bh AS WIDGET-HANDLE NO-UNDO.
DEF INPUT PARAM ipQuery AS CHAR NO-UNDO.
DEF INPUT PARAM ipFields AS CHAR NO-UNDO.

/* Local Variable Definitions --- */
DEF VAR qh AS WIDGET-HANDLE NO-UNDO.
DEF VAR Browse-Hndl AS WIDGET-HANDLE NO-UNDO.
DEF VAR lvInt AS INT NO-UNDO.

/* Create Query */
CREATE QUERY qh.
qh:SET-BUFFERS(bh).

DEFINE FRAME Frame-2
WITH SIZE 132 BY 18 THREE-D NO-LABELS.

CREATE BROWSE Browse-Hndl
ASSIGN
FRAME = FRAME Frame-2:HANDLE
QUERY = qh
TITLE = " "
X = 2
Y = 2
WIDTH = 130
DOWN = 12
VISIBLE = TRUE
SENSITIVE = TRUE
READ-ONLY = NO
COLUMN-SCROLLING = TRUE
SEPARATORS = YES.


Main-Block:

MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
RUN enable_UI.

qh:QUERY-PREPARE(ipQuery).
qh:QUERY-OPEN.

IF NUM-ENTRIES(ipFields) > 1 THEN
DO lvInt = 1 TO NUM-ENTRIES(ipFields):
Browse-Hndl:ADD-LIKE-COLUMN(ENTRY(lvInt,ipFields)).
END.

ENABLE ALL WITH FRAME Frame-2.

IF NOT THIS-PROCEDURE:pERSISTENT THEN
WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.

I have an OK button on the screen and wanted some way to pass back an output that will be enough for the calling program to know what was selected.

I hope you understand what I am trying to acheive as I know I have not explained very well, but I only got back from holidays today and am still getting my brain fully into gear :p

Thanx in advance for any help offered.
Cya.
 
As you scroll up and down in the browser, so the buffer will be kept up to date and its current row will be updated. So if your browser allows only single row selection, finding out which record should be quite easy.

As you are passing the buffer handle into the window. You don't need to return anything to the calling program, except perhaps an indication of whether OK or Cancel was selected. So when OK is pressed, you can just return to the caller.

In your calling program, you can just use the ROWID attribute of the buffer handle to find out which record was selected. Event though the window has been closed, this should remain intact. What you do with it is up to you, but you could make a static read of the selected record as follows:

DEFINE VARIABLE current-rowid AS ROWID NO-UNDO.

ASSIGN current-rowid = bh:ROWID.

FIND Table WHERE ROWID(Table) = current-rowid.
 
Mike Carroll said:
As you scroll up and down in the browser, so the buffer will be kept up to date and its current row will be updated. So if your browser allows only single row selection, finding out which record should be quite easy.

As you are passing the buffer handle into the window. You don't need to return anything to the calling program, except perhaps an indication of whether OK or Cancel was selected. So when OK is pressed, you can just return to the caller.

In your calling program, you can just use the ROWID attribute of the buffer handle to find out which record was selected. Event though the window has been closed, this should remain intact. What you do with it is up to you, but you could make a static read of the selected record as follows:

DEFINE VARIABLE current-rowid AS ROWID NO-UNDO.

ASSIGN current-rowid = bh:ROWID.

FIND Table WHERE ROWID(Table) = current-rowid.

Thanx mate, not sure where my head was yesterday as I was trying to do ROWID(bh). Once again thank you very much mate, this makes it so easy.

Cya.
 
Top