Recent

Author Topic: [SOLVED] Detect if running in the IDE  (Read 3957 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] Detect if running in the IDE
« on: May 29, 2021, 07:32:26 am »
How to detect if my program is running in the IDE?
« Last Edit: May 30, 2021, 01:06:35 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Running in IDE
« Reply #1 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
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Running in IDE
« Reply #2 on: May 29, 2021, 12:35:05 pm »
That will be fine, just where do I set the variable?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Running in IDE
« Reply #3 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.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Running in IDE
« Reply #4 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.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Running in IDE
« Reply #5 on: May 29, 2021, 01:26:37 pm »
In the IDE
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Detect if running in the IDE
« Reply #6 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.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Detect if running in the IDE
« Reply #7 on: May 30, 2021, 01:05:39 pm »
Thanks. What I needed.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: [SOLVED] Detect if running in the IDE
« Reply #8 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"
manlio mazzon gmail

 

TinyPortal © 2005-2018