Lazarus
Using the Lazarus IDE => General => Topic started by: pcurtis on May 29, 2021, 07:32:26 am
-
How to detect if my program is running in the IDE?
-
I bet someone knows a better way but ...
In the IDE, set an environment variable of you choice, if you can find it with GetEnvironmentVariable() you must be in the IDE.
Davo
-
That will be fine, just where do I set the variable?
-
You mean: In the IDE or "under a debugger"
You can run from the IDE, but without debugger.
And you can run in a debugger, but outside the IDE.
-
Afaik on win64, with gdb 7.3.5 environment can not be set. But please double check.
With any other gdb it should work.
-
In the IDE
-
If it is just for your testing or similar you could set some command line parameter in Run/Run Parameters (e.g. /ide). Then you just don't use this parameter when program is run outside of IDE.
In Run Parameters you can set environment variables, also.
-
Thanks. What I needed.
-
I'd like to suggest another way to do that, which may be helpful in some cases.
function InIDE: boolean;
var fn1, fn2: string;
begin
fn1 := ParamStr(0);
fn2 := ChangeFileExt(fn1, '.lpr');
result := FileExists(fn2)
end;
As you can see, if my program is e.g. "myprogram.exe", I look for a file named "myprogram.lpr" in the same folder. If I find it, I know that I'm running the program in my own development folder, which is usually what I want to know, as opposed to the program running in an installed folder such as "Program Files" or "Applications"