Also Problems with a tree

Also Problems with a tree

Postby Silvio.Falconi » Sun Dec 11, 2016 12:01 pm

I compiled an old app and Isaw there is an error when I try to del an item of a tree

I use a simply dbf where the field GEMATERIA is the Master category and GEPCLAVE is the subcategory

DbCreate('GE', {{'GEMATERIA' , 'C', 40, 0} ,;
{'GEPCLAVE' , 'C', 45, 0} ,;
{'MAEJEMPL' , 'N', 5, 0}}, 'DBFCDX')


When I try to del a subcategory it erase the link of the tree and sometimes the record on dbf
When I try to erase the master category it make this error :
Code: Select all  Expand view
  Error occurred at: 12/11/16, 13:00:27
   Error description: Error BASE/1004  Class: 'NIL' has no exported method: AITEMS
   Args:
     [   1] = U  

Stack Calls
===========
   Called from:  => AITEMS( 0 )
   Called from: test.prg => MABORRA( 222 )
   Called from: test.prg => (b)TEST( 46 )
   Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK( 179 )
   Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT( 1687 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3278 )
   Called from:  => SENDMESSAGE( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND( 413 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 905 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 293 )
   Called from: test.prg => TEST( 54 )





to try my error I create a small test sample

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


Static oTree,oImageList


REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO


Function test()
   Local oDlg,oTree
   Local  nBottom   := 22
   Local  nRight    := 58
   Local  nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local  nHeight := nBottom * DLG_CHARPIX_H

 RddSetDefault( "DBFCDX" )


   CreateSampleDbf()

   USE GRUENT ALIAS GE
   INDEX ON UPPER(GE->GEMATERIA)+UPPER(GE->GEPCLAVE) TAG GE01 FOR !Deleted()
   INDEX ON UPPER(GE->GEMATERIA) TAG GE02  FOR   ((!DELETED()) )
   INDEX ON UPPER(GE->GEPCLAVE) TAG GE03  FOR   ((!DELETED()) )

    Poplate_dbf()

 DEFINE DIALOG oDlg     ;
  TITLE "test tree" ;
  SIZE nWidth, nHeight PIXEL          ;
  STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION,  4 )


  oTree = TTreeView():New( 1, 2, oDlg,,,, , 120, 120)

 @ 155,10 say oSay Prompt i18n("Rec.")+tran(GE->(OrdKeyNo()),'@E 999,999')+" / "+tran(GE->(OrdKeyCount()),'@E 999,999') of oDlg size 100,10 pixel



 @ 38, 160 BUTTON oB4 PROMPT "&Cancella" ;
             SIZE 60, 10 PIXEL OF oDlg ACTION MaBorra( oTree,oSay )

  oTree:bChanged = { | oTree | GE->(DbSeek(oTree:GetSelected():Cargo)), oSay:SetText( "Rec."+tran(GE->(RECNO()),'@E 999,999') + " / " + tran(("GE")->(OrdKeyCount()),'@E 999,999') ) }


       ACTIVATE DIALOG oDlg CENTERED    ;
                        ON INIT (oImageList:=LoadImagelist(oDlg),;
                                 BuildTree( oTree),;
                                 oTree:SetImageList( oImageList )  )


       return nil

//--------------------------------------------------------------------//

Function CreateSampleDbf()


    DbCreate('GE', {{'GEMATERIA'  , 'C',   40,   0} ,;
                              {'GEPCLAVE' , 'C',   45,   0} ,;
                              {'MAEJEMPL' , 'N',    5,   0}}, 'DBFCDX')

      close all
      use &('GE') new
      select GE
      if FILE('GRUENT.DBF')
         delete file &('GRUENT.cdx')
         append from &('GRUENT')
         dbcommitall()
         close all
         delete file &('GRUENT.dbf')

      endif
      close all
      rename &('GE.dbf') to &('GRUENT.dbf')

   return nil

//--------------------------------------------------------------------//

 Function MyDelItem( oItem, oDelItem )
   local i

   for i := 1 to Len( oItem:aItems )
       IF oItem:aItems[ i ] == oDelItem
                ADEL( oItem:aItems, i )
                ASIZE( oItem:aItems, LEN( oItem:aItems ) - 1 )
                RETURN NIL
       ENDIF

       MyDelItem( oItem:aItems[ i ], oDelItem )
   next
   RETURN NIL
//-----------------------------------------------------------------------//


FUNCTION RefreshCont( oCont,cdbf)
   oCont:SetText( i18n("Rec.")+tran((cdbf)->(OrdKeyNo()),'@E 999,999')+" / "+tran((cdbf)->(OrdKeyCount()),'@E 999,999') )
  oCont:refresh()
RETURN nil



//------------------------------------------------------------------------------//
function BuildTree( oTree )
   local oLink1, oLink2

   SELECT GE
   
 GE->(DbSetOrder(1))
    GE->(DbGotop())
      DO WHILE ! GE->(EOF())
        if Rtrim(GE->GEPClave) == ""
         oLink1 := oTree:Add(GE->GEMATERIA,0)
         oLink1:Cargo :=  Upper(GE->GEMATERIA)
         oTree:Cargo  := GE->GEMATERIA
     else
         oLink2 := oLink1:Add(GE->GEPClave,1)
         oLink2:Cargo := Upper(GE->GEMATERIA) + Upper(GE->GEPClave)
      endif
      GE->(DbSkip())
   ENDDO

   oTree:SetFocus()
   oTree:expandall()

   return nil


//-----------------------------------------------------------------------------------------------------//


   Function LoadImagelist(oDlg)
   Local  oImageList := TImageList():New()
   Local  oBmp1 ,oBmp2

   oBmp1 := TBitmap():Define( "TREELEVEL1"   , , oDlg )
   oBmp2 := TBitmap():Define( "TREELEVEL2"   , , oDlg )

    oImageList:Add( oBmp1 )
    oImageList:Add( oBmp2 )


  Return oImageList

//-----------------------------------------------------------------------------------------------------//

 function MaBorra( oTree,oCont)

   local oLink       := oTree:GetSelected()
   local cPrompt     := oLink:cPrompt
   local cCargo      := oLink:Cargo
   local nRecno      := GE->(Recno())
   local lMateria    := ( Len(cCargo) <= 40 )
   local  nNext

    if GE->(RecCount()) == 1
      MsgStop("Non è possibile eliminare tutti i record del file. Si prega di inserire un altro record e quindi eliminare questo record")
      retu NIL
   endif

      // oApp():nEdit ++

   GE->(DbSeek(cCargo))
   nRecno :=GE->(Recno())

   if len(oLink:aItems) > 0 //
      MsgStop("non si puo' cancellare la categoria."+CRLF+"bisogna cancellare prima i sottolivelli.")
     // oApp():nEdit --
      return nil
   endif


  if msgYesNo( "¿ Sei sicuro di cancellare questa denominazione ?" + CRLF + ;
                cPrompt)




   // CANCELLO IL TREE
//      oLink:End()   //  <-----------------
     *   TvDeleteItem( oTree:hWnd, oLink:hItem )
     *   MyDelItem( oTree, oLink )


            //  Buscamos el Padre del que cuelga este Item

                oPadre  :=  oLink:GetParent()
                TVDeleteItem(oTree:hWnd, oLink:hItem )

            //  TVDeleteItem borra la rama pero NO elimina de la clase el Item de la rama
                nPosHijoenPadre  := Ascan( oPadre:aItems, {|o| o:hItem == oLink:hItem } )
               IF nPosHijoenPadre > 0

                   ADel ( oPadre:aItems, nPosHijoenPadre )
                   ASize( oPadre:aItems, Len(oPadre:aItems)-1 )
                ENDIF





    SELECT GE
      GE->(DbSkip())
      nNext := GE->(Recno())
      GE->(DbGoto(nRecno))

      GE->(DbDelete())
      GE->(DbPack())
      GE->(DbGoto(nNext))

      IF GE->(EOF()) .or. nNext == nRecno
         GE->(DbGoBottom())
      ENDIF



                ENDIF
             oTree:refresh()




   if oCont != nil
   /*
      RefreshCont(oCont,"GE") */

      GE->(DbSeek(oTree:GetSelected():Cargo))
      oCont:SetText( "Rec."+tran(GE->(RECNO()),'@E 999,999') + " / " + tran(("GE")->(OrdKeyCount()),'@E 999,999') )
      oCont:refresh()
   endif

  // oApp():nEdit --


RETURN NIL


//-----------------------------------------------------------------------------------------------------//

Function Poplate_dbf()
If GE->(eof())
         GE->(DbAppend())
         REPLACE GEMateria WITH "Category1"
        GE->(DbAppend())
        REPLACE GEMateria WITH "Category1"
        REPLACE GEPClave  WITH "Subcategory1"
         GE->(DbAppend())
         REPLACE GEMateria WITH "Category2"
        GE->(DbAppend())
        REPLACE GEMateria WITH "Category2"
        REPLACE GEPClave  WITH "Subcategory2"
        GE->(DbCommit())

Endif
return nil

 



my test.rc

Code: Select all  Expand view
1 24 "WindowsXP.Manifest"
TREELEVEL1   BITMAP  ".\TREE\LIVELLO1.BMP"
TREELEVEL2   BITMAP  ".\TREE\LIVELLO2.BMP"
 


the bitmaps
Image

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Also Problems with a tree

Postby Antonio Linares » Tue Dec 13, 2016 10:54 am

Dear Silvio,

Thats not a small test :-)

Please provide something simpler
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42093
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Also Problems with a tree

Postby Silvio.Falconi » Tue Dec 13, 2016 10:59 am

how I can make ?
I not Know make a small test to see my problem ....

on treer5 run ok
when I wanted change the source od the treee from treer5 to linares's tree I had had many problems
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Also Problems with a tree

Postby Antonio Linares » Tue Dec 13, 2016 11:24 am

Silvio,

After this line:

oPadre := oLink:GetParent()

you should check if oPadre is nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42093
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Also Problems with a tree

Postby Silvio.Falconi » Mon Dec 19, 2016 1:33 pm

yes is nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 115 guests