bb.donnay-software.com

Donnay Software Web Forums
It is currently Mon May 20, 2019 6:27 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Mar 08, 2019 9:14 pm 
Offline
User avatar

Joined: Tue Jul 28, 2015 5:15 am
Posts: 93
Hi all

How can I clear all buttons when I press a button and get them back after.
Here is an example.
There is 3 buttons, A, B, C. I would like to have all buttons A, B, and C destroyed while I execute BA() and get the buttons back after the execution of BA().

Thanks

Code:
// In the example, pushbuttons are created that
// output text in an XbpCrt window.
// How do I destroy all the buttons when I click on A ?

   #include "Appevent.ch"

   PROCEDURE Main
   
      LOCAL nEvent, mp1, mp2, oXbp
     
      CLS

      // Create first pushbutton
      oXbp := XbpPushButton():new( , , {50,20}, {100,40} )
      oXbp:caption := "A"
      oXbp:create()
      oXbp:activate := {|| BA( oXbp ) }

      // Create second pushbutton
      oXbp := XbpPushButton():new( , , {200,20}, {100,40} )
      oXbp:caption := "B"
      oXbp:create()
      oXbp:activate := {|| BB( oXbp ) }

      // Create last pushbutton
      oXbp := XbpPushButton():new( , , {350,20}, {100,40} )
      oXbp:caption := "C"
      oXbp:create()
      oXbp:activate := {|| BC( oXbp ) }

      // Event loop = Program navigation
      nEvent := 0
      DO WHILE nEvent <> xbeP_Close
     
         nEvent := AppEvent( @mp1, @mp2, @oXbp )
         @ 05, 22 SAY PadR( Var2Char( nEvent ), 10 )
         
         IF VALTYPE(mp1) = "N" .AND. mp1 < 1000 .AND. mp1 <> 0
            k = mp1
            mp1 = 0
            @ 10, 22 SAY PadR( Var2Char( k ), 10 )
            k = 0
         ELSE
            oXbp:HandleEvent( nEvent, mp1, mp2 )
            k = LASTKEY() // TO GET THE FUNCTIONS
            @ 10, 22 SAY PadR( Var2Char( k ), 10 )
            k = 0
         ENDIF
           
         
         // @ 10, 00 SAY SPACE(80) // CLEAR ON SCREEN
         
      ENDDO
     
      ? "quitting"
      inkey(1)
   RETURN
   
   FUNCTION BA( oXbp, oB2 )
      oXbp:destroy()

      mGET = SPACE(30)
      @ 10, 12 SAY "BA        "
      @ 12, 12 GET mGET
      SET CURSOR ON
      READ
      SET CURSOR OFF
     
      CLEAR SCREEN

      oXbp := XbpPushButton():new( , , {50,20}, {100,40} )
      oXbp:caption := "A"
      oXbp:create()
      oXbp:activate := {|| BA( oXbp ) }
   RETURN

   FUNCTION BB( oXbp )
      @ 10, 12 SAY "BB        "
   RETURN

   FUNCTION BC( oXbp )
      @ 10, 12 SAY "BC        "
   RETURN



Top
 Profile  
 
PostPosted: Sat Mar 09, 2019 4:53 am 
Offline
User avatar

Joined: Tue Jul 28, 2015 5:15 am
Posts: 93
Here is a solution.
Save the object reference into an array.
You will be able to destroy them all.

Thanks.

AP



Code:
// In the example, pushbuttons are created that
// output text in an XbpCrt window.
// How do I destroy all the buttons when I click on A ?

   #include "Appevent.ch"

   PROCEDURE Main
   
      PRIVATE nEvent, mp1, mp2, oXbp
     
      aPushButtons := {}
     
      CLS
     
      sCreatePushButtons()

      // Event loop = Program navigation
      nEvent := 0
      DO WHILE nEvent <> xbeP_Close
     
         nEvent := AppEvent( @mp1, @mp2, @oXbp )
         @ 05, 22 SAY PadR( Var2Char( nEvent ), 10 )
         
         // Catch the key after a GUI event
         IF VALTYPE(mp1) = "N" .AND. mp1 < 1000 .AND. mp1 <> 0
            k = mp1
            mp1 = 0
            @ 10, 22 SAY PadR( Var2Char( k ), 10 )
            k = 0
         ELSE
            oXbp:HandleEvent( nEvent, mp1, mp2 )
            k = LASTKEY() // TO GET THE FUNCTIONS
            @ 10, 22 SAY PadR( Var2Char( k ), 10 )
            k = 0
         ENDIF
         
      ENDDO
     
      ? "Quitting"
      inkey(1)
   RETURN
   
   FUNCTION BA()

      sDestroyPushButtons()   

      mGET = SPACE(30)
      @ 10, 12 SAY "BA        "
      @ 12, 12 GET mGET
      SET CURSOR ON
      READ
      SET CURSOR OFF
     
      CLEAR SCREEN

      sCreatePushButtons()
     
   RETURN .T.

   FUNCTION BB()
      @ 10, 12 SAY "BB        "
   RETURN .T.

   FUNCTION BC()
      @ 10, 12 SAY "BC        "
   RETURN .T.

   FUNCTION sCreatePushButtons()
 
      // Create first pushbutton
      oXbp := XbpPushButton():new( , , {50,20}, {100,40} )
      oXbp:caption := "A"
      oXbp:create()
      oXbp:activate := {|| BA() }
      AADD(aPushButtons,oXbp)

      // Create second pushbutton
      oXbp := XbpPushButton():new( , , {200,20}, {100,40} )
      oXbp:caption := "B"
      oXbp:create()
      oXbp:activate := {|| BB() }
      AADD(aPushButtons,oXbp)

      // Create last pushbutton
      oXbp := XbpPushButton():new( , , {350,20}, {100,40} )
      oXbp:caption := "C"
      oXbp:create()
      oXbp:activate := {|| BC() }
      AADD(aPushButtons,oXbp)

   RETURN .T.
   
   FUNCTION sDestroyPushButtons()
   
      FOR i := 1 TO LEN(aPushButtons)
         aPushButtons[i]:DESTROY()
      NEXT
      aPushButtons := {}

   RETURN .T.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group