Form Designer - Help Sample

You need some new stunning features ? Tell us here.
atiaust
New User
New User
Posts: 7
Joined: Thu Mar 13, 2014 3:26 am

Form Designer - Help Sample

Post by atiaust »

I am very new to PB..
I am trying to understand the Form Designer example in PB5.21 LTS Demo
Have created 2 forms MainWindow.pbf and DateWindow.pbf and 1 code file Main.pb

Main.pb
----------------------------------------------------------------------------------------------------------------------------

Code: Select all

XIncludeFile "MainWindow.pbf" ; Include the first window definition
  XIncludeFile "DateWindow.pbf" ; Include the second window definition
  
  ;OpenMainWindow() ; Open the first window. This procedure name is always 'Open' followed by the window name
  ;OpenDateWindow() ; Open the second window
  OpenWindow_0()
  OpenWindow_1()
  
  ; The event procedures, as specified in the 'event procedure' property of each gadget
  Procedure OkButtonEvent(EventType)
    Debug "OkButton event"
  EndProcedure
  
  Procedure CancelButtonEvent(EventType)
    Debug "CancelButton event"
  EndProcedure
  
  Procedure TrainCalendarEvent(EventType)
    Debug "TrainCalendar event"
  EndProcedure
  
  ; The main event loop as usual, the only change is to call the automatically
  ; generated event procedure for each window.
  Repeat
    Event = WaitWindowEvent()
    
    Select EventWindow()
      Case MainWindow
        Window_0_Events(Event) ; This procedure name is always window name followed by '_Events'
        
      Case DateWindow
        Window_1_Events(Event)
        
    EndSelect
    
  Until Event = #PB_Event_CloseWindow ; Quit on any window close

---------------------------------------------------------------------------------------------------------------------------------
MainWindow.pbf

Code: Select all

Global Window_0

Global OKButton, CancelButton

Declare OkButtonEvent(EventType)
Declare CancelButtonEvent(EventType)

Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
  OKButton = ButtonGadget(#PB_Any, 100, 250, 100, 25, "OK")
  CancelButton = ButtonGadget(#PB_Any, 360, 250, 100, 25, "Cancel")
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 OKButton
          OkButtonEvent(EventType())          
        Case CancelButton
          CancelButtonEvent(EventType())          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
-----------------------------------------------------------------------------------------
DateWindow.pbf

Code: Select all

Global Window_1

Global TrainCalendar

Procedure OpenWindow_1(x = 0, y = 0, width = 600, height = 400)
  Window_1 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
  TrainCalendar = DateGadget(#PB_Any, 180, 120, 200, 30, "")
EndProcedure

---------------------------------------------------------------------------------------------

When I try to run I get an error message:
Line36: Window_1_Events() is not a function(or not available in demo version), array, list, map or macro
This is in Main.pb

If I comment the line out the program runs but opens both windows with Window_1 over Window_2 (both windows open)
Can someone provide some info on this please? or an example that works.

Thanks
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: Form Designer - Help Sample

Post by Bisonte »

The Formdesigner is only for build one Window. If you want to use more windows, you have to fit your "main.pb" to your needs.

In your case, there is no Window_1_Event() procedure, so the error occurs.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
atiaust
New User
New User
Posts: 7
Joined: Thu Mar 13, 2014 3:26 am

Re: Form Designer - Help Sample

Post by atiaust »

Thank you Bisonte,

I just figured out I had accidentally unchecked the 'Generate Events procedures' in the Window_1 form.

The program now compiles and runs but doesn't do anything when I click on any of the buttons.

Any other suggestions appreciated.

New DateWindow.pbf

Code: Select all

Global Window_1

Global TrainCalendar

Declare TrainCalendarEvent(EventType)

Procedure OpenWindow_1(x = 0, y = 0, width = 600, height = 400)
  Window_1 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
  TrainCalendar = DateGadget(#PB_Any, 180, 120, 200, 30, "")
EndProcedure

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

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case TrainCalendar
          TrainCalendarEvent(EventType())          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
Thanks
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Form Designer - Help Sample

Post by TI-994A »

atiaust wrote:...The program now compiles and runs but doesn't do anything when I click on any of the buttons....
Hello atiaust, and welcome to the wonderful world of PureBasic!

Simply replace the window names in the event loop of Main.pb to their assigned variables, Window_0 and Window_1, as follows:

Code: Select all

  Repeat
    Event = WaitWindowEvent()
    
    Select EventWindow()
      Case Window_0
        Window_0_Events(Event) ; This procedure name is always window name followed by '_Events'
        
      Case Window_1
        Window_1_Events(Event)
        
    EndSelect
    
  Until Event = #PB_Event_CloseWindow ; Quit on any window close
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
atiaust
New User
New User
Posts: 7
Joined: Thu Mar 13, 2014 3:26 am

Re: Form Designer - Help Sample

Post by atiaust »

Thanks TI-994A,

That did the trick.
Its very frustrating when you follow the examples (From the help file) that have inbuilt enhancements.....

I only started to play with PureBasic a couple of days ago. Haven't done anything in basic since back in VB6 days.

So far it looks excellent :D
Great job by the designers.

Thanks again.
Post Reply