Help: Events handling with the Form Designer

You need some new stunning features ? Tell us here.
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Help: Events handling with the Form Designer

Post by barryem »

Could someone please tell us new users where to look for updated informaton? I've just been reading this page and fighting to make it work and when I get to the bottom it tells me it's no longer appropriate. That information might be better at the top if that's possible and maybe it could include some idea where to look for updated information if there is any.

Thanks,
Barry
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Help: Events handling with the Form Designer

Post by Julian »

In the form designer, select the window then select Form->Toolbox in the right pane. Under Layout, un-check "Generate events procedure?". This will stop PB from generating the code for the window i.e.:

Code: Select all

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
This is the part that is depricated, as support for callbacks are now included and are much much better than the old WaitWindowEvent and WindowEvent into a Select statement methods as above.

Search "BindEvent" in the help for an example of how to start using this method, if you get stuck, let me know and I'll pop up an example.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Help: Events handling with the Form Designer

Post by TI-994A »

Julian wrote:...un-check "Generate events procedure?". This will stop PB from generating the code for the window ... This is the part that is depricated, as support for callbacks are now included and are much much better than the old WaitWindowEvent and WindowEvent into a Select statement methods as above.

Search "BindEvent" in the help for an example of how to start using this method...
Hello Julian. Please allow me to interject with some points.

Firstly, and most importantly, it should be noted that the event loop and corresponding procedures are still an integral part of the PureBasic programming structure, and have in no way been deprecated or replaced. The WindowEvent()/WaitWindowEvent() commands in the event loop form the very backbone of any PureBasic window-based program.

While callbacks are useful, it would simply not be practical to bind every event to one. They are intended for use in conjunction with the WindowEvent()/WaitWindowEvent() commands (as required), and not in lieu of them:
The PureBasic Manual - BindEvent() wrote:Bind an event to a callback. It's an additional way to handle events in PureBasic, which works without problem with the regulars WindowEvent() / WaitWindowEvent() commands.
They remain as options in the form designer properties and preferences settings only to afford developers the choice of implementing them either within the form code itself, or in external modules. Not as a do-away.

In clarification, it is the old form designer that is deprecated, superseded by the current form designer which revamps some old features and spots some new ones as well.

Please do correct me if I'm wrong. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Help: Events handling with the Form Designer

Post by Julian »

Well spotted TI and correct, I got up too early and hadn't had my caffeine infusion.

As mentioned above, to get a simple blank form working use the following code in a separate .pb file in the same folder the myform.pbf

Code: Select all

XIncludeFile "myform.pbf"

OpenWindow_0()

Repeat
  Event = WaitWindowEvent()
  Window_0_Events(Event)
Until event = #PB_Event_CloseWindow
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Help: Events handling with the Form Designer

Post by barryem »

Thanks for explaining. I did read up on BindEvent and kind of understood that. I'm coming from PowerBasic and this is all kind of different. I think the problem is that I really don't understand the program flow in Purebasic yet.

I'll keep reading and trying to understand it. What I've been trying to do is to make a very simple form with the form designer with a button and a text box and have a main program that calls that. Then when the button is pressed a number in the text box is incremented or the text is changed in some way to indicate it.

The problem I keep running into is how to connect a variable in the main file and the form file. Well, other problems too but I'm so confused I don't know what they are yet. :)

Any simple example, the simpler the better, of a pb file and an accompanying pbf file that has some variable that both affect would be great. In the meantime I'll keep playing with it. Or maybe it's more proper to say I'll keep letting it play with me. :)

Thanks,
Barry
Post Reply