Hello,
I have some problems with TreeItem class, I am working with tree inside xbrowse but I have problems deleting an element, when it isn't at end all work ok, but when I try to delete the last element there are an error in this part of code ( ttreeitem line 252)
it is complety logical but the error is about oLast data, and it isn't defined in the class ttreeitem, this is defined in tlinklist class
The same problem for the first element and logic is the same
This is a simple adapted sample
some idea?
regards
Marcelo
I have some problems with TreeItem class, I am working with tree inside xbrowse but I have problems deleting an element, when it isn't at end all work ok, but when I try to delete the last element there are an error in this part of code ( ttreeitem line 252)
if ::oNext == nil .or. ::oNext:nLevel < ::nLevel
oTree:oLast := ::oPrev
else
::oNext:oPrev := ::oPrev
endifit is complety logical but the error is about oLast data, and it isn't defined in the class ttreeitem, this is defined in tlinklist class
The same problem for the first element and logic is the same
This is a simple adapted sample
#include "FiveWin.Ch"
#include "xbrowse.ch"
STATIC aData
//----------------------------------------------------------------------------//
#xtranslate bmp( <c> ) => ".\" + <c> + ".bmp"
//----------------------------------------------------------------------------//
function Main()
CreateTestData()
TreeBrowse()
return (0)
//----------------------------------------------------------------------------//
static function TreeBrowse
local oDlg, oBrw, oFont, nn, oItem
local aTot := { 0, 0 }
local aColors := { { CLR_WHITE, CLR_GREEN }, ;
{ CLR_BLACK, RGB(255,255,180) }, ;
{ CLR_BLACK, CLR_WHITE } }
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 600,500 PIXEL ;
TITLE "Xbrowse Tree" FONT oFont
@ 20,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
CELL LINES NOBORDER FOOTERS FASTEDIT;
ON DBLCLICK MSGINFO( oBrw:oTreeItem:nLevel )
oBrw:SetTree( MakeTree( aTot ), { bmp( "open" ), bmp( "close" ), bmp( "go" ) } )
ADD TO oBrw PICTURE "999,999,999" HEADER "Sales" DATA oBrw:oTreeItem:Cargo[ 1 ]
ADD TO oBrw PICTURE "999,999,999" HEADER "Margin" DATA oBrw:oTreeItem:Cargo[ 2 ]
//oBrw:aCols[3]:bEditWhen := {|| oBrw:oTreeItem:Cargo[3] == 2 }
oBrw:aCols[3]:nEditType := EDIT_GET
oBrw:aCols[3]:bOnPostEdit := {|o,x| oBrw:oTreeItem:Cargo[2] := x }
oBrw:aCols[3]:lAutoSave := .T.
oBrw:CreateFromCode()
oBrw:OpenAll()
oBrw:bPastEof := {|| oItem := oBrw:oLast ,;
IF( oBrw:oTreeItem:Cargo[2] = 99,;
( oItem := oItem:Add( 'AAAAA' ),;
oItem:Cargo := {1,2,99} ), ) ,;
oBrw:refresh() }
@ 1, 40 BUTTON "ADD" OF oDlg SIZE 30,10 PIXEL ACTION ( IF( oBrw:oTreeItem:oTree != NIL,;
oItem := oBrw:oTreeItem:oLast, ;
oItem := oBrw:oLast ), ;
oItem := oItem:Add( 'AAAAA' ),;
oItem:Cargo := {1,2,99},;
oBrw:refresh() )
@ 1, 80 BUTTON 'DEL' OF oDlg SIZE 30,10 PIXEL ACTION ( msginfo( oBrw:oTreeItem:classname() ) ,;
IF( oBrw:oTreeItem:oTree != NIL, ;
oBrw:oTreeItem:delete( oBrw:oTreeItem:oTree ),;
oBrw:oTreeItem:delete( oBrw:oTreeItem ) ) ,;
oBrw:refresh() )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function MakeTree( aTot )
local oTree
local cRegion, cCountry
local oRegion, oCountry, i
TREE oTree
FOR i := 1 TO 10
TREEITEM oRegion PROMPT aData[i,1] CARGO { aData[i,1], 2, i }
NEXT
ENDTREE
return oTree
//----------------------------------------------------------------------------//
static function createTestData()
LOCAL REGION,COUNTRY,CITY
local i,n,m
aData := {}
for i := 1 to 10
AADD( aData, { 'DATO ' + STR(i), STR(I), STR(i), i, i } )
next i
return nil
//----------------------------------------------------------------------------//some idea?
regards
Marcelo