Page 1 of 1

How can I tell if running from stand-alone or compiler?

Posted: Mon Jan 19, 2009 11:03 pm
by WilliamL
Easy one...

How can the program tell if it is running from the compiler or in stand-alone?

Is there a constant (with a value) or something else?

Posted: Tue Jan 20, 2009 12:45 am
by akj
I'm guessing as I don't have a MAC but I would have thought that in practice (though not always in theory) this code would do what you want:

Code: Select all

If LCase(GetPathPart(ProgramFilename()))= LCase(GetTemporaryDirectory())
  MessageRequester("Run Type", "Running from the IDE")
Else
  MessageRequester("Run Type", "Running as a stand-alone EXE")
EndIf

Posted: Tue Jan 20, 2009 12:50 am
by case
there's no difference when running a pb executable from the ide or a compiled version , the compiler create an .exe then run it.

but you can set yourself a way to kow it

put something like

Code: Select all

global standalone.b=1 ; change it to 0 for a non standalone build
then use the variable for your program to know if it run from the compiler or not...

Posted: Tue Jan 20, 2009 12:52 am
by Kaeru Gaman
if the only way is a manual setting, you could also use a constant.
#STANDALONE = #False
would be better than a global variable...

Posted: Tue Jan 20, 2009 12:53 am
by case
akj wrote:I'm guessing as I don't have a MAC but I would have thought that in practice (though not always in theory) this code would do what you want:

Code: Select all

If LCase(GetPathPart(ProgramFilename()))= LCase(GetTemporaryDirectory())
  MessageRequester("Run Type", "Running from the IDE")
Else
  MessageRequester("Run Type", "Running as a stand-alone EXE")
EndIf

that may not work if you compile the program in the same directory of the final build , like i do for some code that need files to be present.

Posted: Tue Jan 20, 2009 1:04 am
by WilliamL
Thanks all.

I've been using the variable method as shown below.

Code: Select all

FilePath.s=GetCurrentDirectory()
If Len(AFilePath)<5
   ; gives / (one char) (this is stand-alone mode)
    FilePath=ProgramFilename() ; this works in stand-alone mode
    PBMode=0 ; in stand-alone
Else
  ;gives full file path
    PBMode=1 ; in compile mode
EndIf

Posted: Tue Jan 20, 2009 2:00 am
by Kaeru Gaman
this is only that long practicable, as long you don't compile the temporary exe into the source directory to access ressources in subdirectories more easily...

Posted: Tue Jan 20, 2009 3:17 am
by freak
You can just go the Compiler Options -> Constants and enable the #PB_Editor_CreateExecutable constant. This way you know when the code is compiled from the editor.

Posted: Tue Jan 20, 2009 3:59 am
by WilliamL
Thanks, freak, now we all know!
#PB_Editor_CreateExecutable
If enabled, this constants holds a value of 1 if the code is compiled with the "Create Executable" menu or 0 if "Compile/Run" was used.
Tried it and it works!

Re: How can I tell if running from stand-alone or compiler?

Posted: Tue Jan 20, 2009 12:11 pm
by PB
> How can the program tell if it is running from the compiler or in stand-alone?

For Windows (and probably cross-platform) I've been using this:

Code: Select all

CompilerIf #PB_Compiler_Debugger
  ; Do runtime code here.
CompilerElse
  ; Do final exe code here.
CompilerEndIf
No need to enable anything in every source. ;)

Posted: Tue Jan 20, 2009 2:52 pm
by Kaeru Gaman
@freak

always something new to discover...

thanx for that tip!


@PB

... afaik you can compile a standalone exe INCLUDING debugger support ...

Posted: Tue Jan 20, 2009 8:50 pm
by akj
@freak,

As most PB users would expect a constant that seems to relate to the compilation process to be mentioned in the 'Compiler Directives' section of the Help manual, I would like to request that a reference to (i.e. mention of) #PB_Editor_CreateExecutable be added to that help section. Pretty please.

Alternatively, can a facility be provided for [a copy of] the Help pages to be freely editable by registered PureBasic users? Of course, the edits would need to be vetted by 'The Management' but it would be a good way to quickly improve the quality and scope of the PB documentation which in my opinion is still quite minimalist.

Posted: Tue Jan 20, 2009 9:06 pm
by freak
akj wrote:@freak,

As most PB users would expect a constant that seems to relate to the compilation process to be mentioned in the 'Compiler Directives' section of the Help manual, I would like to request that a reference to (i.e. mention of) #PB_Editor_CreateExecutable be added to that help section. Pretty please.
Its not a feature of the compiler. Its a feature of the IDE, and it is documented in the IDE documentation. (if you use the commandline compiler, the constant will not be added).
akj wrote:Alternatively, can a facility be provided for [a copy of] the Help pages to be freely editable by registered PureBasic users? Of course, the edits would need to be vetted by 'The Management' but it would be a good way to quickly improve the quality and scope of the PB documentation which in my opinion is still quite minimalist.
There was a wiki once. It was taken down due to lack of user interest.

Posted: Tue Jan 20, 2009 9:13 pm
by PB
> you can compile a standalone exe INCLUDING debugger support

How? The docs say it's never done that way, for speed reasons.

Posted: Tue Jan 20, 2009 9:21 pm
by ts-soft
PB wrote:> you can compile a standalone exe INCLUDING debugger support

How? The docs say it's never done that way, for speed reasons.
Use the demoversion :lol: