I’ve struggled a bit to understand why the .PBF concept should contain any code logic. I feel that its use is primarily a means of allowing the form designer to re-create the code for the gadgets, without overwriting the programmer’s logic.
If this assumption is correct, and .PBF is only there to specify parameters of gadgets, isn’t there a good case for storing only those gadgets and nothing else? I used the very helpful post by @TI-994A to understand the concept - at viewtopic.php?f=22&t=64684. It seems from looking at this link, that there has been a conceptual change in the past, because he refers to the following…
The latter option is of course now absent from PB, but it seems that even the Generate Event option would be better if this code is placed in the .PB instead.File menu – Preferences - In the left panel of the dialog that appears, select Form, then in the dialog window, make sure that the Generate Event procedure and Generate Event Loop options are selected.
Is there anything wrong with the suggested minimalist concept below, other than the fact that when we make a forms-design change, PB will recreate the global variables? I moved the global declaration to the top of the .PB, above the XIncludeFile. This incidentally is TI-994A’s example restructured. It would be interesting to gain other developers' better insights here, before I embark on something. Thanks.
Code: Select all
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file
Procedure OpenWindow_0(x = 0, y = 0, width = 300, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "My Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Button_0 = ButtonGadget(#PB_Any, 160, 70, 100, 25, "Click Me")
Text_0 = TextGadget(#PB_Any, 30, 20, 100, 25, "This is a label")
String_0 = StringGadget(#PB_Any, 30, 70, 100, 25, "")
EndProcedure
Code: Select all
Global Window_0
Global Button_0, Text_0, String_0
XIncludeFile "MyForm.pbf"
Procedure buttonEvent(eventType.i)
text$ = GetGadgetText(String_0) ;get the text from the text box (identifier = String_0)
SetGadgetText(Text_0, text$) ;and place it in the label (identifier = Text_0)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
buttonEvent(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
Repeat
event = WaitWindowEvent()
Until Window_0_Events(event) = #False