I want to share one of my most important selfmade procedures which is called: ProgramFilePath()
The procedure took into consideration that I do not always use "Create temporary executable in the source directory".
Because I made the implementation in a include file I have to do the following in every main source file.
Code: Select all
; Internal use in INCLUDE files according to the respective main source file
;
#PB_Compiler_MainFilePath = #PB_Compiler_FilePath ; this kept the file path of the main source
#PB_Compiler_MainFilename = #PB_Compiler_Filename ; -"- file name -"-
#PB_Compiler_MainFile = #PB_Compiler_File ; -"- file path and name -"-
; <PathToMySourceCodes>\SharedCodes.pbi
Code: Select all
; ---------------------------------------------------------------------------------------------------------------------
; ProgramFilePath()
;
; returns always (in all situations) the correct path to the executable program file (<name>.exe)
;
Procedure.s ProgramFilePath() ; returns file path -- of the executable (or the source file if in development)
Protected result.s
CompilerIf #PB_Editor_CreateExecutable ; .. at runtime (easy)
result = GetPathPart(ProgramFilename())
CompilerElse ; .. at development time
CompilerIf Defined(PB_Compiler_MainFile, #PB_Constant)
If #PB_Compiler_MainFilename = "PB_EditorOutput.pb" ; set constant in main file, than this works in include files)
Debug "● HINT: " + #PB_Compiler_Procedure + "() with unsaved main file returns ''"
result = "" ; no valid program path
Else
result = #PB_Compiler_MainFilePath
EndIf
CompilerElse ; Defined(PB_Compiler_MainFile, #PB_Constant)
Debug "● HINT: " + #PB_Compiler_Procedure + "() "
Debug "; The following constants are missing in main source code file: "
Debug "#PB_Compiler_MainFilePath = #PB_Compiler_FilePath ; this kept the file path of the main source "
Debug "#PB_Compiler_MainFilename = #PB_Compiler_Filename ; file name "
Debug "#PB_Compiler_MainFile = #PB_Compiler_File ; file path and name "
Debug ""
CompilerEndIf
CompilerEndIf
ProcedureReturn result
EndProcedure