PureBasic has the 'Declare' keyword because, as noted in the documentation, sometimes a procedure needs to call another procedure which isn't declared before its definition.
http://www.purebasic.com/documentation/ ... dures.html
Unfortunately if you want to order your procedures in your source code in any way that makes most sense to you, such as alphabetically or perhaps just sequentially as you create them, you have to Declare them first. Then any changes you make to a Procedure declaration must be repeated for the Declare declaration as well, a duplication of effort.
To address this, I wrote a simple program I call the 'PureBasic Forward Declare Builder'. This application simply reads your source code file and automatically outputs a separate file of Declare statements for every Procedure. You can then simply put an IncludeFile of that Declare file at the top of your source file. This allows you to declare your Procedures in any order that you prefer. Thanks to the excellent integration of external tools capabilities built into the PB IDE, the building of this Declares file can be automatic.
Setup steps:
1) Create an executable of the Forward Declare Builder code below and save the executable wherever you prefer.
2) In the PB IDE, go to Tools > Configure Tools ... and choose 'New'
3) Configure the Edit Tool Settings as follows:
Commandline: The location and name of your Forward Declare Builder executable from step 1. For example, C:\PBTools\PB_FDB.exe
Arguments: %FILE
Name: Forward Declare Builder
Event to trigger the tool: Before Compile/Run (or whichever you prefer but unfortunately 'Sourcecode saved' doesn't appear to work at this time)
Wait until tool quits - checked
Run hidden - checked
Enable tool on a per-source basis - checked (optional but recommended - if you only want to build the Forward Declares file for specific source files, see step 6)
4) Hit OK. Ensure the new Forward Declare Builder tool is checked in the Configure Tools window.
5) At the top of your application source code file add the IncludeFile with suffix "_Declares.pbi". For example, if your source code file is "YourSourceFile.pb" then IncludeFile "YourSourceFile_Declares.pbi" (the Forward Declares file will be created in the same directory as your source code file, so if necessary enter the appropriate path)
6) In the PB IDE, go to Compiler > Compiler options ... tab Compile/Run, check the Forward Declare Builder tool in "Execute tools".
You're done! Now every time you Compile/Run your source file the Forward Declare Builder will quickly run first and build a fresh updated Declare include file.
You will need to repeat steps 5 and 6 for each source file.
Optionally, you can just run the Forward Declare Builder code manually without all the above setup and it will simply prompt you for your source code file and generate the declares file.
Limitations:
- Assumes entire procedure declaration is on 1 line.
- Doesn't currently work with "Runtime" procedure declarations.
Please let me know if you have any questions. Thanks!

PureBasic Forward Declare Builder:
Code: Select all
;
; PureBasic Forward Declare Builder
; Author: USCode
;
; September 23, 2010 - Original version
; September 10, 2013 - Updated for PB IDE Tools integration
;
EnableExplicit
Define.s sLine, sFile, sSource
If CountProgramParameters()
sSource = ProgramParameter(0)
Else
sSource= OpenFileRequester("PB source file", "", "PureBasic (*.pb,*.pbi)|*.pb;*.pbi|All files (*.*)|*.*", 0)
EndIf
If FileSize(sSource) > 0
If ReadFile(0, sSource)
sFile = Left(sSource, Len(sSource) - Len(GetExtensionPart(sSource)) - 1) + "_Declares.pbi"
If CreateFile(1, sFile)
While Not Eof(0)
sLine = Trim(ReadString(0))
If Left(sLine,9) = "Procedure" And Left(sLine,15) <> "ProcedureReturn"
WriteStringN(1, "Declare" + Right(sLine, Len(sLine) - 9))
EndIf
Wend
CloseFile(1)
EndIf
CloseFile(0)
EndIf
EndIf
End