Page 1 of 1

Form Designer - Help Sample

Posted: Fri Mar 14, 2014 9:17 am
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

Re: Form Designer - Help Sample

Posted: Fri Mar 14, 2014 9:54 am
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.

Re: Form Designer - Help Sample

Posted: Fri Mar 14, 2014 10:16 am
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

Re: Form Designer - Help Sample

Posted: Fri Mar 14, 2014 10:34 am
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

Re: Form Designer - Help Sample

Posted: Fri Mar 14, 2014 11:31 am
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.