I am trying to find the current record in a XBrowse.
The highlighted row is the current record.
I am using FWH 1805 and xHarbour, so things may be different now.
The behavior is consistent throughout all versions from the beginning of xbrowse till now.
I would assume that when you left-double-click on a record in an xBrowse it would become the "current" record.
Not exactly the double-click, but the left button press makes the clicked record as the current record. Because double-click involves left button press, the clicked record becomes the current record.
I should also mention that if you move the highlight to another record (and use a button to get the current record description) it also shows the first record as the current record.
This is not possible, if you correctly defined the xbrowse.
Looks like you are browsing a different datasource (eg. the DBF Alias() directly) and querying a different datasource (eg. the Database Object).
In this case, while the xbrowse
navigates the DBF alias, the Database Object's buffer still contains the values of the first record unchanged.
Please make sure to use the clause "DATASOURCE oCustomers" in the command "@ r,c XBROWSE oBrwCust ... DATASOURCE oCustomers ...". If you omitted this xbrowse would display the default alias.
If this is a bug, has it been corrected?
If it is not a bug, then how can I get the CUSTNO of the currently selected record?
There is no bug at all either in xbrowse or tdatabase. Hence, no need for correction.
Please re-check your program.
If we see your source code, we can advise you where the bug is.
Here is the problem:
- Code: Select all Expand view RUN
// This always shows data from the first record in the indexed database, NOT the currently highlighted record in the xbrowse
oBrwCust:bLDblClick:= {| oCustomers | msgInfo(oCustomers:custno), msgInfo(oCustomers:last) }
This codeblock has a serious flaw.
Are you sure you are using exactly the same codeblock in your application?
With this codeblock, double click should result in a run-time error and will never show the msginfo().
Because the way the codeblock is written, the variable oCustomers does not refer to the database object but to a numeric value (row in pixels where the user clicked) inside the codeblock and a numeric value can not have any methods/datas.
While writing such codeblocks, we need to know/ascertain what are the parameters supplied by the evaluating method/procedure while evaluating the codeblock.
Please see line no.2038 of window.prg (FWH1805)
- Code: Select all Expand view RUN
return Eval( ::bLDblClick, nRow, nCol, nKeyFlags, Self )
The xbrowse object evaluates the bLDblCkick codeblock with 4 parameters nRow, nCol, nKeyFlags and Self.
If we declare the codeblock as
- Code: Select all Expand view RUN
{ |param1,param2,param3,param4| <execution code> }
parameters 1 to 4 (whatever names we use) are assigned the values of nRow, nCol, nFlags and Self (xbrowse object). That is the reason, why oCustomers (first and the only parameter declared) gets a numeric value of nRow.
This is better:
- Code: Select all Expand view RUN
oBrwCust:bLDblClick := { |r,c,f,o| If( Empty( o:oDbf ), msginfo( "not browsing database object" ), msginfo( o:oDbf:First + o:oDbf:Last ) ) }
This is a small test program to demonstrate that with a correctly defined xbrowse, you will get the expected results. Please copy the program to fwh\samples folder and build with buildx.bat:
- Code: Select all Expand view RUN
#include "fivewin.ch"
REQUEST DBFCDX
function Main()
local oCustomers, oDlg, oFont, oBrw
oCustomers := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
DEFINE FONT oFont NAME "CALIBRI" SIZE 0,-16
DEFINE DIALOG oDlg SIZE 700,350 PIXEL TRUEPIXEL FONT oFont TITLE FWVERSION
@ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oCustomers AUTOCOLS LINES NOBORDER
WITH OBJECT oBrw
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:bLDblClick := { |r,c,f,o| ShowRec( o ) }
//
:CreateFromCode()
END
@ 20,20 BUTTON "Show Record" SIZE 200,30 PIXEL OF oDlg ACTION ShowRec( oBrw )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function ShowRec( oBrw )
WITH OBJECT oBrw:oDbf
? :RecNo(), :ID, :First, :Last
END
oBrw:SetFocus()
return nil