xBrwTree.prg Sample with empty Database

xBrwTree.prg Sample with empty Database

Postby Rick Lipkin » Wed Nov 27, 2013 6: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: Select all  Expand view

==========
   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: Select all  Expand view

#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
 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrwTree.prg Sample with empty Database

Postby nageswaragunupudi » Thu Nov 28, 2013 2: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
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests