push buttons in CRT hybride

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

push buttons in CRT hybride

#1 Post by alepap »

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: Select all

// 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


User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

Re: push buttons in CRT hybride

#2 Post by alepap »

Here is a solution.
Save the object reference into an array.
You will be able to destroy them all.

Thanks.

AP


Code: Select all

// 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.

Post Reply