FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrwTree.prg Sample with empty Database
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
xBrwTree.prg Sample with empty Database
Posted: Wed Nov 27, 2013 06:20 PM
To All

From my previous post, I found the sample xBrwTree.prg which works great if you have records in the Customer.Dbf .. unfortunitly, if Customer.dbf is empty, you get the following error ..

Code (fw): Select all Collapse
==========
   Path and name: C:\FWH1203\samples\xbrwtree.exe (32 bits)
   Size: 2,139,136 bytes
   Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 9444)
   FiveWin  Version: FWHX 12.03
   Windows version: 5.1, Build 2600 Service Pack 3

   Time from start: 0 hours 0 mins 0 secs 
   Error occurred at: 11/27/13, 13:13:33
   Error description: Error BASE/1004  Class: 'NIL' has no exported method: CARGO
   Args:
     [   1] = U   

Stack Calls
===========
   Called from:  => CARGO( 0 )
   Called from: xbrwtree.prg => MAIN( 19 )


I have the Same problem adapting this code to ADO when there are no records in the recordset. I know there must be a simple answer, here is the Sample xBrwTree.prg code .. to run, you will need to put the Customer.dbf in the same folder.

Many Thanks
Rick Lipkin
Code (fw): Select all Collapse
#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 "DBF shown as a tree with XBrowse"

   @ 0, 0 XBROWSE oBrw OF oWnd LINES CELL

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

   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] HEADER "Last"  // <-- errors here on empty database
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] HEADER "First"

 *  oBrw:nMarqueeStyle   := MARQSTYLE_HIGHLROW
   oBrw:Last:nEditType  := EDIT_GET_BUTTON
   oBrw:Last:bEditBlock := {|row, col, oCol| oBrw:GoLeftMost(),MsgInfo("Test") }  // repair   
   
   
   
   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "State & City"

   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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrwTree.prg Sample with empty Database
Posted: Thu Nov 28, 2013 02:27 AM

When there are no records, use a Tree with one blank tree item.
eg:
TREE oTree
TREEITEM Space(20) CARGO { Space(20), Space(20) }
ENDTREE

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion