Lazarus

Using the Lazarus IDE => General => Topic started by: pcurtis on May 29, 2021, 07:32:26 am

Title: [SOLVED] Detect if running in the IDE
Post by: pcurtis on May 29, 2021, 07:32:26 am
How to detect if my program is running in the IDE?
Title: Re: Running in IDE
Post by: dbannon on May 29, 2021, 11:44:47 am
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
Title: Re: Running in IDE
Post by: pcurtis on May 29, 2021, 12:35:05 pm
That will be fine, just where do I set the variable?
Title: Re: Running in IDE
Post by: Martin_fr on May 29, 2021, 12:39:14 pm
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.
Title: Re: Running in IDE
Post by: Martin_fr on May 29, 2021, 12:40:06 pm
Afaik on win64, with gdb 7.3.5 environment can not be set. But please double check.
With any other gdb it should work.
Title: Re: Running in IDE
Post by: pcurtis on May 29, 2021, 01:26:37 pm
In the IDE
Title: Re: Detect if running in the IDE
Post by: dseligo on May 30, 2021, 12:31:56 pm
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.
Title: Re: Detect if running in the IDE
Post by: pcurtis on May 30, 2021, 01:05:39 pm
Thanks. What I needed.
Title: Re: [SOLVED] Detect if running in the IDE
Post by: Manlio on September 20, 2021, 06:11:12 pm
I'd like to suggest another way to do that, which may be helpful in some cases.

Code: [Select]
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"
TinyPortal © 2005-2018