OpenNameWindow() not working

You need some new stunning features ? Tell us here.
RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

OpenNameWindow() not working

Post by RBart »

Hi,

I am trying out PureBasic.
So I want to work with multiple forms.
I created a project and added two files, Main.pb and a MainWindow.pbf just like the example.
The second form is not created yet so I commented it out. I would think that by running the Main.pb the form MainWindow.pbf would open.
https://www.purebasic.com/documentation ... _form.html.
But I get a nasty compiler error, 'OpenMainWindow() is not a function, arry, list or macro.'
I am on a Linux machine with Ubuntu 22.04.5 LTS with version 6.20 demo from PureBasic.

What am I doing wrong? The example looks easy...

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
Thanks in advance
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OpenNameWindow() not working

Post by mk-soft »

Wellcome ;)

What does your MainWindow.pbf look like?
Show me the code
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

Re: OpenNameWindow() not working

Post by RBart »

Code: Select all

;
; This code is automatically generated by the Form Designer.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures need to be put in another source file.
;

Global Window_0

Global Button_0


Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Maximize)
  Button_0 = ButtonGadget(#PB_Any, 280, 70, 100, 25, "test")
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

RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

Re: OpenNameWindow() not working

Post by RBart »

changed line 4 to: OpenWindow_0() ; Open the first window. This procedure name is always 'Open' followed by the window name
Error message is gone but form is not visible.
RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

Re: OpenNameWindow() not working

Post by RBart »

ok. I figured it out, the name of the file is different from the dimensioned name in the code:

Code: Select all

  XIncludeFile "MainWindow.pbf" ; Include the first window definition
;   XIncludeFile "DateWindow.pbf" ; Include the second window definition
  
  OpenWindow_0()  ; Open the first window. This procedure name is always 'Open' followed by the window name
                  ;   OpenDateWindow() ; Open the second window
    
  ; 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
;         DateWindow_Events(Event)
        
    EndSelect
    
  Until Event = #PB_Event_CloseWindow ; Quit on any window close
RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

Re: OpenNameWindow() not working

Post by RBart »

got the second form working too.
You need to change all the naming in the code or use the automatic generated names in the code. Would be nice if the name of the file was used when automatic generating the code file for a form.

Find/Replace speeds up de change of default naming to more reasonable naming.

The second form:

Code: Select all

;
;
; This code is automatically generated by the Form Designer.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures need to be put in another source file.
;

Global frmPureBasic ; manualy changed the name


Procedure OpenfrmPureBasic(x = 0, y = 0, width = 600, height = 400) ; manualy changed the name
  frmPureBasic = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu); manualy changed the name
EndProcedure

Procedure frmPureBasic_Events(Event); manualy changed the name
  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


Main.pb code:

Code: Select all

XIncludeFile "MainWindow.pbf" ; Include the first window definition
XIncludeFile "purebasic.pbf"  ; Include the second window definition
  
OpenWindow_0()  ; Open the first window. This procedure name is always 'Open' followed by the window name
OpenfrmPureBasic() ; Open the second window
    
  ; 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 purebasic
        frmPureBasic_Events(Event)
        
    EndSelect
    
  Until Event = #PB_Event_CloseWindow ; Quit on any window close
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OpenNameWindow() not working

Post by mk-soft »

You must change the name of the variable or of the gadgets. Then you don't have to search and replace.
I also don't like the setting that #PB_Any is used. I prefer to work with constants
The global settings for form can be found in the Preferences menu.

Maybe you should not start with the Form Designer, but create the windows and gadgets by hand.
That way you can use the examples in the help and in the examples folder.

I have provided my template for small test programmes for this purpose. It contains everything you need for an executable programme and proper event management.
Just go through it and read the functions with "F1".

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButtonOk
  #MainButtonCancel
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
    ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButtonOk
              ;
            Case #MainButtonCancel
              ;
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Once you understand the basics, you might want to have a look at my EventDesigner (for lazy people) for creating all the codes of form files.
But only then ;)
Last edited by mk-soft on Sat May 24, 2025 3:00 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

Re: OpenNameWindow() not working

Post by RBart »

To change the name in the code can be done by changing it in the Properties under Variable
RBart
New User
New User
Posts: 7
Joined: Sun May 04, 2025 11:18 am

Re: OpenNameWindow() not working

Post by RBart »

mk-soft wrote: Sat May 24, 2025 2:54 pm You must change the name of the variable or of the gadgets. Then you don't have to search and replace.
I also don't like the setting that #PB_Any is used. I prefer to work with constants
The global settings for form can be found in the Preferences menu.

Maybe you should not start with the Form Designer, but create the windows and gadgets by hand.
That way you can use the examples in the help and in the examples folder.

I have provided my template for small test programmes for this purpose. It contains everything you need for an executable programme and proper event management.
Just go through it and read the functions with "F1".

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButtonOk
  #MainButtonCancel
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
    ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButtonOk
              ;
            Case #MainButtonCancel
              ;
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Once you understand the basics, you might want to have a look at my EventDesigner (for lazy people) for creating all the codes of form files.
But only then ;)
Thanks a lot. Will do
Post Reply