#PB_Editor_CreateExecutable

Everything else that doesn't fall into one of the other PB categories.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

#PB_Editor_CreateExecutable

Post by Josh »

Can anybody say to me, why I have to activate #PB_Editor_CreateExecutable in Compiler-Options before using? Why is this constant not set by default, when I'm starting my program from Ide?
sorry for my bad english
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: #PB_Editor_CreateExecutable

Post by Demivec »

Josh wrote:Can anybody say to me, why I have to activate #PB_Editor_CreateExecutable in Compiler-Options before using? Why is this constant not set by default, when I'm starting my program from Ide?
I imagine that one of the reasons is that you have to name the executible that is created and where it will be written (I think these can be set as a part of projects). Also, when you are creating the executible you don't usually want to execute it at the same time, it may be part of a group of other files that all need to be produced (i.e. assembled, compiled, etc.) before being used.

Testing and debugging a source code is far more common than creating a final executible.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: #PB_Editor_CreateExecutable

Post by Josh »

Demivec wrote:Testing and debugging a source code is far more common than creating a final executible.
As far as I know, this compiler-option does nothing other, than it makes the constant #PB_Editor_CreateExecutable disposable for the compiler. There is no executable created or not, if this constant is set or not.
sorry for my bad english
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: #PB_Editor_CreateExecutable

Post by Demivec »

Josh wrote:
Demivec wrote:Testing and debugging a source code is far more common than creating a final executible.
As far as I know, this compiler-option does nothing other, than it makes the constant #PB_Editor_CreateExecutable disposable for the compiler. There is no executable created or not, if this constant is set or not.
I apologize, I misunderstood your question when I first read it and thought it was simply about the need to having a 'create executable' menu option.

Returning to your actual question, wouldn't the #PB_Editor_CreateExecutable constant be useful to allow a program to create code for test data or make logging options active if the program is not the final executable?

Perhaps something like this:

Code: Select all

;If code is compiled without using the compiler option that creates
;the #PB_Editor_CreateExecutable constant it will set up code for
;logging data to either a file or the debugger window (based on the
;value of #UseDebugForLoggingFunctions).

;If the #PB_Editor_CreateExecutable constant is activated in the
;compiler options it will not include code for the logging
;functions and make them non-existent for the resulting executable.



CompilerIf Not Defined(PB_Editor_CreateExecutable, #PB_Constant)
  #PB_Editor_CreateExecutable = #False ;If not defined in compiler options or otherwise, set it to #False
CompilerEndIf

CompilerIf #PB_Editor_CreateExecutable = 1
  
  ;don't create logging code if this is an executable, create do-nothing substitutes instead
  Macro createLogFile(filename)
    0
  EndMacro
  Macro logToFile(fileID, text)
  EndMacro
  Macro closeLogFile(fileID)
  EndMacro  
  
CompilerElse
  
  #UseDebugForLoggingFunctions = #True ; set to #False to use file output, #True = debugger output window
  
  ;create logging functions
  Procedure createLogFile(filename.s)
    CompilerIf #UseDebugForLoggingFunctions
      a = -1
    CompilerElse
      a = OpenFile(#PB_Any, filename)
    CompilerEndIf
    
    If Not a
      MessageRequester("Error", "Couldn't create log file.")
    EndIf
    ProcedureReturn a
  EndProcedure
  
  Procedure logToFile(fileID, text.s)
    If fileID = -1 
      Debug Str(fileID) + ": " + text.s
    Else
      WriteStringN(FileID, text)
    EndIf
  EndProcedure
  
  Procedure closeLogFile(fileID)
    If IsFile(fileID)
      CloseFile(fileID)
    EndIf
  EndProcedure

CompilerEndIf

Define fileID = createLogFile("J:\filename.log") ;0 = function not available

For i = 1 To 10
  logToFile(fileID, "Line #" + i)
  ;some processing functions
Next

closeLogFile(fileID)
If code is compiled without using the compiler option that creates the #PB_Editor_CreateExecutable constant it will set up code for logging data to either a file or the debugger window (based on the value of #UseDebugForLoggingFunctions).

If the #PB_Editor_CreateExecutable constant is activated in the compiler options it will not include code for the logging functions and make them non-existent for the resulting executable.

In any case there are 3 distinct compiling choices: one for debugging, one for testing and one for the final executable. This constant helps distinguish between the two that are not debugging options.

I agree that it may be better to simply replace it with a compiling constant that is always available. It should only depend on if it is possible to always know if something is a final executable or not when it is being compiled.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: #PB_Editor_CreateExecutable

Post by Josh »

Hohoho, you are really, really near to my current project. I have three states too:

1) #IsSimModeRunning = #True (is equivalent to #PB_Editor_CreateExecutable = #False, only a better understandable name)
2) #IsSimModeRunning = #False (is equivalent to #PB_Editor_CreateExecutable = #True, only a better understandable name)
3) #CompileFinalExe, this constant I have set in my code at the absolute top. In this case, no SimMode, no Logfile, no additional checks in code and some other stuff is not created.

Like you described, I could set my third state in the compiler-options, but I think, I w'ont, because in 2 years I'm looking annoyed what I have created there and don't think at the small check-box-tick. Probably I will create a project with two destinations, than is all clear in 5 years too.

But back to the topic:
I think, the checkbox in compiler-options for #PB_Editor_CreateExecutable is useless and confusing. The same is with #PB_Editor_BuildCount and #PB_Editor_CreateExecutable at the same place in compileroptions. I don't see no reason why here must be a checkbox.
sorry for my bad english
Post Reply