Add some buttons to your CRT app

If you are converting a text-based Clipper application, a FoxPro application or just writing an application from scratch, use this forum for your eXpress++ questions.
Post Reply
Message
Author
User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

Add some buttons to your CRT app

#1 Post by alepap »

So now you have express++, you added the dialogs and it starts to look good. It´s time to play with buttons.

Basically, instead of using a loop with k = LASTKEY() you need to add the event management system. In other words, you need to monitor the keys used on the keyboard, but also all the action done with a mouse. You still can catch the LASTKEY() and do whatever you use to do with it, but, a PushButton will also execute a function just like a set key.

Here is some code to show you an example.

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