bfernhout wrote: Mon Sep 16, 2024 9:31 am... there was one tiny glitch. When saving a file you can click on the save file icon but you can not press F5 to save the file. ...
Wow! I totally didn't catch that mistake. It was meant to be
Ctlr+S / Cmd+S.
Apparently, during video editing, I had re-used one of the text blocks, namely the one to execute a
RUN command, but I must have forgotten to change the text in the third line.
Thanks for pointing that out. I'll try to upload a correction soon.
bfernhout wrote: Mon Sep 16, 2024 9:31 am... When a file is saved and keep the extension PBF. the file still had the option to turn to the form editor. And the events in that file can't be programmed for use. ...
This is done by design.
Forms are meant to be standalone objects which are created and managed exclusively by the Form Designer. Any
manual amendments or additions to the form file code
will be purged.
Programs should utilise these
.PBF form files as objects by including them with the
XIncludeFile function. The events of the forms should then be
handled by the hosting program according to the event-procedure parameters specified in the form designer. Please allow me to demonstrate this.
Here is the default code generated by the
Form Designer before any form specifications are changed and before any gadgets are added:
Code: Select all
Global Window_0
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
EndProcedure
Now, in the properties window of the
Form Designer, select the
Generate events procedure? option, like so:
The form code should now look like this, with the additional
Window_0_Events() procedure:
Code: Select all
Global Window_0
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
EndProcedure
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
Next, let's add a single button to the form and set these two properties for it:
Now, the form code includes:
1. the declaration of the new button gadget captioned as "BUTTON" in
OpenWindow_0()
2. the call to a procedure named
buttonHandler() in
Window_0_Events() for handling the button gadget
Code: Select all
Global Window_0
Global Button_0
Declare buttonHandler(EventType)
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
Button_0 = ButtonGadget(#PB_Any, 10, 10, 100, 25, "BUTTON")
EndProcedure
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()
Case Button_0
buttonHandler(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Save the above form file as
myForm.pbf, and create the following code file:
Code: Select all
XIncludeFile "myForm.pbf"
OpenWindow_0()
; the procedure to handle the button as specified in the form
Procedure buttonHandler(eType)
Debug "Button Clicked!"
EndProcedure
Repeat
; relay all the events to the form
If Window_0_Events(WaitWindowEvent()) = #False : Break : EndIf
ForEver
Finally,
SAVE THE CODE FILE IN THE SAME FOLDER AS THE FORM FILE (the code file name is not important here), and run it.
The code file relays all the events to the form file, and the form file responds and routes the events as specified. In this example:
1. the form file returns a
FALSE value when it receives the close-window event
(default behaviour), causing the program to end.
2. the form file routes execution to the
buttonHandler() procedure when it receives the button gadget event.
Very simple!
The code in the form file remains modular and unchanged, and all programming logic resides within the code file. The form file can be continuously updated and modified within the
Form Designer without affecting the code logic,
as long as any changes to the event logic are updated in the code file accordingly.
I hope this clarifies the matter.
