About PureBasic

@SteveW I would like your opinion or any suggestions for improvements on this code structure:

This is my Main.pb code. LauncherForm.pbf is the windows created using the Form Designer. LauncherForm.pbi contains all of the code to handle the gadget events for that Window. My question is this a good format for all of the additional Windows I’m going to need? Having the pbf and pbi file pairs continuing to be added at the top of the Main.pb file? Or is there a better way to do this?

Global SystemDatabase

XIncludeFile "LauncherForm.pbf"
XIncludeFile "LauncherForm.pbi"

XIncludeFile "SystemDb.pbi"

UseSQLiteDatabase()
InitKeyboard()
; EnableExplicit

VerifySystemDatabaseExists()

OpenLauncherForm()  
LoadRecentDatabaseList()

Repeat
  Event = WaitWindowEvent()
  
  Select EventWindow()
    Case LauncherForm
      LauncherForm_Events(Event) 
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow 

If SystemDatabase > 0
  CloseDatabase(SystemDatabase)
EndIf

PureBasic is a single-pass compiler so you may want to include all the *.pbf files before the *.pbi files so the compiler has seen all window / gadget constants before any functions reference them ( e.g. a handler in window x references a gadget on window y )

Repeat

Until Event = #PB_Event_CloseWindow 

That loop will terminate the application when ANY window is closed. While you only have one window that’s OK but you’ll want to revisit that once your app has more than one.

I’d also recommend using EnableExplicit which helps catch typos

The PureBasic forum is here and there are many helpful members so it’s worth joining up.

2 Likes

Yep, I always use EnableExplicit mode myself :sunglasses:

1 Like