Finding XBrowse current record

Finding XBrowse current record

Postby James Bott » Thu Jul 01, 2021 8:12 pm

Nages, or anyone:

I am trying to find the current record in a XBrowse. First let me state that I am using FWH 1805 and xHarbour, so things may be different now.

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) }


I would assume that when you left-double-click on a record in an xBrowse it would become the "current" record. The clicked record does become the highlighted record, but the current database record is still be the first record in the browse, as the CUSTNO and LAST name of the first record are always shown when you click on any record in the browse.

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.

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?

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Finding XBrowse current record

Postby AngelSalom » Sat Jul 03, 2021 6:25 pm

Try with

Code: Select all  Expand view  RUN

oBrwCust:custno:Value
 


(adapt custno to the name of the desired column)
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Finding XBrowse current record

Postby James Bott » Sat Jul 03, 2021 8:24 pm

Angel,

OMG, that works! I spent two days trying to figure that out. I would have never guessed to add ":value".

You just made my day!

Now I am going to record this in my Fivewin notes file.

Have a great day.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Finding XBrowse current record

Postby AngelSalom » Sun Jul 04, 2021 6:27 am

I'm glad it works for you
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Finding XBrowse current record

Postby nageswaragunupudi » Sun Jul 04, 2021 11:36 am

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
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Finding XBrowse current record

Postby James Bott » Tue Jul 06, 2021 11:46 pm

Nages,

Thanks for all the input, it helps. I went down this road because it was the only thing I could get working.

However, what I would really like to figure out, is how to find the currently highlight row no matter how the user gets there, click, double-click, arrow keys, mouse, etc. The reason I want to do this is that I want to show two browses on the same dialog and synch the second one with the first one. So, for instance, I can show customers in the first browse and the highlighted customer's invoices in the second browse.

Any ideas?

Thanks,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Finding XBrowse current record

Postby TimStone » Wed Jul 07, 2021 12:31 am

James,

I have to run out right now, but later tonight, or in the morning, I will send you how to do this using tData ... it works well.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Finding XBrowse current record

Postby James Bott » Wed Jul 07, 2021 2:01 am

Tim,

Great. Thanks!

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Finding XBrowse current record

Postby nageswaragunupudi » Wed Jul 07, 2021 3:02 am

Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oStates, oCust
   local oWnd, oBar, oBrwStates, oBrwCust, oFont

   FWNumFormat( "A", .t. )  // American formatting, with commas
   SET DELETED ON

   oCust    := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
   if oCust:OrdNumber( "STATE" ) == 0
      oCust:CreateIndex( "TMP", "STATE", "STATE", .f., .f., .t. )
   endif
   oCust:SetOrder( "STATE" )

   oStates  := TDataBase():Open( nil, "STATES", "DBFCDX", .t. )
   oStates:SetRelation( oCust, "CODE", .t. )
   oStates:GoTop()
   oCust:GoTop()

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE WINDOW oWnd TITLE FWVERSION
   oWnd:SetFont( oFont )
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007

   @ oBar:nHeight, 0 XBROWSE oBrwStates SIZE 250, 0 PIXEL OF oWnd ;
      DATASOURCE oStates AUTOCOLS CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrwStates
      :bChange := { || oBrwCust:GoTop(), oBrwCust:MakeTotals(), oBrwCust:Refresh() }
      //
      :CreateFromCode()
   END

   @ oBar:nHeight, 250 XBROWSE oBrwCust SIZE 0,0 PIXEL OF oWnd ;
      DATASOURCE oCust ;
      COLUMNS "STATE", "ID", "FIRST", "CITY", "SALARY" ;
      CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrwCust
      :State:bFooter       := { || oBrwCust:nLen }
      :Salary:nFooterType  := AGGR_SUM
      :MakeTotals()
      //
      :CreateFromCode()
   END

   ACTIVATE WINDOW oWnd MAXIMIZED
   RELEASE FONT oFont

return nil
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Finding XBrowse current record

Postby TimStone » Wed Jul 07, 2021 4:49 am

James,

Here is a code snippet ...

Code: Select all  Expand view  RUN

    REDEFINE  XBROWSE oLbxs ;
      DATASOURCE aSrvHis ;
      HEADERS " Date ", " Paid ", " Order # ", sLbl[3], " Parts ", " Labor ", " Sublet ", " Total ", " ID " ;
      COLUMNS 1,2,3,4,5,6,7, 8, 9  ;
      ID 1970 OF oDlgh ;
      ON CHANGE ( oHistory:CheckHistory( aSrvHis[oLbxs:nArrayAt,3] ), oLbxd:refresh( ) ) ;
      UPDATE

            // Provide the header gradient
            oLbxs:bClrGrad := aPubGrad
            // Set the styles
            oLbxs:nMarqueeStyle := MARQSTYLE_HIGHLROW
            oLbxs:nColDividerStyle := LINESTYLE_RAISED
            oLbxs:nRowDividerStyle := LINESTYLE_RAISED
            oLbxs:nHeadStrAligns  := AL_CENTER
        //  oLbxs:nStretchCol := STRETCHCOL_LAST
   
    REDEFINE  XBROWSE oLbxd ;
      DATASOURCE aParItm ;
      HEADERS " Details ", " " ;
      COLUMNS 1, " " ;
      FONT fntfixed SIZES 600 ;
      ID 1971 OF oDlgh ;
      ON DBLCLICK oHistory:HistoryDrillDown( aParItm[oLbxd:nArrayAt,2], aParItm[oLbxd:nArrayAt,3] ) ;
      UPDATE

            // Provide the header gradient
            oLbxd:bClrGrad := aPubGrad
            // Set the styles
            oLbxd:nMarqueeStyle := MARQSTYLE_HIGHLROW
            oLbxd:bClrSel = { || { 16777215, 15512898 } }
            oLbxd:nHeadStrAligns  := AL_CENTER
            oLbxd:nStretchCol := STRETCHCOL_LAST
           

 


In this case, the datasource is an array, but you can also do it with a database. You can ignore the functions ... they are specialized processes.

Here is another snippet of code that employs tRecord. When the record changes, tRecord is loaded from the new ( highlighted ) row, and then the fields are all individually displayed. The browse is in the lower half of the screen, and all the data in the upper half. The customer can edit the data, and do a save ( tRecord:save() ). I'm rather rushed tonight, but will be available again later on Friday if you have need for more clarification. These were simply cut from existing code ...

Code: Select all  Expand view  RUN

   // Create the browse control
   REDEFINE  XBROWSE oLbx1 ;
      DATASOURCE oEditWork:oWorkParts  ;
      HEADERS "Quantity", "Partnumber", "Description", "Total", "Tax?", "Sold by", " Status ", " Labor ", " Source ", " " ;
      COLUMNS "parqun", "parnum", "pardes", "partot", "partax", "parcom", "status", "pargrp","paruf2", " " ;
      JUSTIFY 2,,,,,, 2 ;
      PICTURE "#####.##","@X","@X","#####.##",,"@X","@X","@X","@X" ;
      ID 486 OF  oEditWork:oFld:aDialogs[ 2 ] ;
      ON CHANGE ( oEditWork:oWorkPartsr:load(), oEditWork:SetWorkParts2(), cVenNam := ShoVnd( oEditWork:oWorkPartsr:parven, oEditWork:aVnd ), oEditWork:oFld:update() )  ;
      UPDATE
   oLbx1:aCols[ 5 ]:SetCheck( nil, .T. )
   // Provide the header gradient
   oLbx1:bClrGrad := aPubGrad
   // Set the styles
   oLbx1:nMarqueeStyle := MARQSTYLE_HIGHLROW
   oLbx1:nColDividerStyle := LINESTYLE_RAISED
   oLbx1:nRowDividerStyle := LINESTYLE_RAISED
   oLbx1:nHeadStrAligns  := AL_CENTER
   oLbx1:nStretchCol := STRETCHCOL_LAST

 
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Finding XBrowse current record

Postby James Bott » Wed Jul 07, 2021 7:01 am

Nages and Tim:
Thanks for the examples! I will be looking at them ASAP.

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Finding XBrowse current record

Postby goosfancito » Mon Nov 15, 2021 8:54 am

Hola.

Intento "sincronizar" dos tablas con MARIADB y xbrowse pero al querer hacer como en el ejemplo usar el metodo "setrelation" me dice que el metodo no esta para MARIADB, alguien tiene algun ejemplo?

quiero hacer que en un xbrowsw aparezcan las facturas y cuando hago click en alguna de ellas muestre en el otro xbrowse el detalle de dicha factura.

Mi codigo
Code: Select all  Expand view  RUN
 TEXT into cSql
   Select
   a.id AS c1,
   a.idsucursal AS c2,
   a.idfactura AS c3,
   a.fecha AS c4,
   a.idcontacto AS c5,
   a.subtotal AS c6,
   a.total AS c7,
   b.id AS c8,
   b.nombre AS c9
   FROM tbventas AS a
   Left JOIN tbsucursal AS b ON a.idsucursal = b.id
   ENDTEXT
   
   DEFINE WINDOW oWnd
   
   oQry   := ::oCnx:QUERY( cSql )

   @ 0, 0 XBROWSE oBrw SIZE 550, - 100 PIXEL ;
   DATASOURCE oQry ;
   LINES CELL ;
   autocols ;
   OF oWnd

   WITH OBJECT oBrw
      :bchange := { || oQry:Requery(), oBrw1:GoTop(), oBrw1:Refresh() }
   END WITH

   oBrw:CreateFromCode()

   //----------( )----------

   TEXT into cSql1
   Select
   a.id AS c1,
   a.idventa AS c2,
   a.fecha AS c3,
   a.formadepago AS c4,
   a.entregado AS c5
   FROM tbctacte AS a
   WHERE a.idventa = ?
   ENDTEXT

   oQry1   := ::oCnx:QUERY( cSql1, { oQry:FieldGet( "c1" ) } )

   @ 0, 560 XBROWSE oBrw1 SIZE 650, - 100 PIXEL ;
   DATASOURCE oQry1 ;
   LINES CELL ;
   autocols ;
   OF oWnd

   oBrw1:CreateFromCode()

   ACTIVATE WINDOW oWnd MAXIMIZED


gracias.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 76 guests