Page 1 of 2

oTree for xBrowse sample...

Posted: Sat Oct 11, 2008 8:59 am
by fraxzi
Hi!

Anybody with working sample using Tree for xBrowse for DBFCDX table....


Best Regards,
Frances

Posted: Sat Oct 11, 2008 9:03 am
by anserkk
Did you try the \FWH\Samples\TestXbr3.Prg

Check menu Tree Browse.

Regards

Anser

Posted: Sat Oct 11, 2008 9:07 am
by fraxzi
Yes I tried but I cant work it by (alias)->field....

I dont use ADO.


Regards

Posted: Tue Oct 14, 2008 1:00 am
by fraxzi
Anyone?

Posted: Tue Oct 14, 2008 9:01 am
by Antonio Linares
Frances,

You can use the source code for MakeTree() in samples\TestXbr3.prg

Just use the DBF instead of an ADO recordset. The source code is almost the same.

Posted: Tue Oct 14, 2008 10:27 am
by Detlef Hoefner
Antonio Linares wrote:Frances,

You can use the source code for MakeTree() in samples\TestXbr3.prg

Just use the DBF instead of an ADO recordset. The source code is almost the same.
Antonio,

i'm also very interested in a sample how to use this tree browse with dbf files.
Unfortunatelly it's not so easy to find a replacement for the 'union' clause of a sql query.

Could you please provide a pure dbf sample for this useful feature or give us some tips?
This woulds be great.

Thanks and regards,
Detlef

Posted: Tue Oct 14, 2008 2:56 pm
by Antonio Linares
Frances, Detlef,

Here you have a working example:

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()   

   local oWnd, oBrw

   USE Customer
   INDEX ON Field->State TO State
   SET ORDER TO "State"
   GO TOP
   
   DEFINE WINDOW oWnd TITLE "DbfTree"

   @ 0, 0 XBROWSE oBrw OF oWnd LINES CELL

   oBrw:SetTree( BuildTree() )

   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "State"

   oWnd:oClient = oBrw
   
   ACTIVATE WINDOW oWnd
   
return nil   

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := RecNo()
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := RecNo()
               TREE
            endif   
         endif   
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := RecNo()
         endif   
         SKIP
      enddo
      ENDTREE
   ENDTREE

   GO TOP

return oTree

Posted: Tue Oct 14, 2008 2:58 pm
by Antonio Linares
Image

Posted: Tue Oct 14, 2008 3:10 pm
by Detlef Hoefner
Antonio,

this is working great! :)

Many thanks for the sample,
Detlef

Posted: Tue Oct 14, 2008 3:16 pm
by Antonio Linares
Using bitmaps in the tree:

Test.prg

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()   

   local oWnd, oBrw

   USE Customer
   INDEX ON Field->State TO State
   SET ORDER TO "State"
   GO TOP
   
   DEFINE WINDOW oWnd TITLE "DbfTree"

   @ 0, 0 XBROWSE oBrw OF oWnd LINES CELL

   oBrw:SetTree( BuildTree(), { "open", "close", "go" } )

   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "State"

   oWnd:oClient = oBrw
   
   ACTIVATE WINDOW oWnd
   
return nil   

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := RecNo()
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := RecNo()
               TREE
            endif   
         endif   
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := RecNo()
         endif   
         SKIP
      enddo
      ENDTREE
   ENDTREE

   GO TOP

return oTree
Test.rc

Code: Select all

open  BITMAP "c:\fwh\bitmaps\16x16\folder2.bmp"
close BITMAP "c:\fwh\bitmaps\16x16\folder.bmp"
go    BITMAP "c:\fwh\bitmaps\16x16\go.bmp" 
Image

Posted: Tue Oct 14, 2008 4:33 pm
by Antonio Linares
With multiple columns:

test.prg

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()   

   local oWnd, oBrw

   USE Customer
   INDEX ON Field->State TO State
   SET ORDER TO "State"
   GO TOP
   
   DEFINE WINDOW oWnd TITLE "DbfTree"

   @ 0, 0 XBROWSE oBrw OF oWnd LINES CELL

   oBrw:SetTree( BuildTree(), { "open", "close", "go" } )

   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] HEADER "Last"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] HEADER "First"

   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "State"

   oWnd:oClient = oBrw
   
   ACTIVATE WINDOW oWnd
   
return nil   

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := { Space( 20 ), Space( 20 ) }
               TREE
            endif   
         endif   
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := { Customer->Last, Customer->First }
         endif   
         SKIP
      enddo
      ENDTREE
   ENDTREE

   GO TOP

return oTree
Image

Posted: Wed Oct 15, 2008 5:57 am
by anserkk
It's a very good sample.

What changes should I make on the above sample to display the tree if the user hit enter key also. Right now tree is displayed only when the user double click on the Data.

Regards

Anser

Posted: Wed Oct 15, 2008 7:03 am
by Antonio Linares
In order to open the browse tree with the keyboard (return key) this change in Class TXBrowse is required:

Code: Select all

METHOD KeyChar( nKey, nFlags ) CLASS TXBrowse
...
      case nKey == VK_RETURN
         oCol := ::SelectedCol()
         if oCol:nEditType > 0
            ...
         else
            If( ::oTreeItem:oTree != nil,( ::oTreeItem:Toggle(), ::Refresh() ),) // new !!!
         endif
...
In the example, to select the entire row:

Code: Select all

   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
Image

Posted: Wed Oct 15, 2008 7:50 am
by anserkk
Thankyou Mr.Antonio,

Modifying the xBrowse.Prg means either I have to include the modified xBrowse.Prg along with my project

or

I should generate FiveH.Lib (Harbour) and FiveHx.Lib (xHarbour) to generate a modified lib to reflect the changes made in xBrowse.Prg. Am I right ?.

Is there a batch file available to generate FiveH.Lib and FiveHx.Lib ?.

Sorry for asking questions which is out of topic of this particular thread. I thought it might be useful for beginners like me who read this thread.

Would have been better if we had some solution without altering the xBrowse source.

Regards

Anser

Posted: Wed Oct 15, 2008 8:20 am
by Antonio Linares
Anser,

You can do it both ways:

1: Modify xbrowse.prg and compile it and link it as another PRG of your application.

2: Modify xbrowse.prg and compile it and update FiveH.lib or FiveHX.lib (if you use Harbour or xHarbour)

To rebuild the library you can use this batch file:

Code: Select all

for %%f in (*.prg) do c:\harbour\bin\harbour %%f /n /ic:\fwh\include;c:\harbour\include 
for %%f in (*.c) do c:\bcc55\bin\bcc32 -c -Ic:\bcc55\include;c:\harbour\include %%f 
for %%f in (*.obj) do c:\bcc55\bin\tlib fiveh.lib -+ %%f /0 /P32,,