Seems detecting if your application is started from the Lazarus IDE can be a little bit of a challenge.
Under Delphi one could use the DebugHook variable, but that does not work under Lazarus.
Having seen plenty of trick - none of the automatically doing what its supposed to do, I figured I go for this approach;
function RunningInProjectFolder:boolean;
begin
Result := FileExists(ChangeFileExt(ParamStr(0), '.lpr'));
end;
This detects if your application was started from the project directory by seeing if the .lpr file exists.
This works cross-platform, but the caveat is that it will think its running in the IDE if you started the executable in the project directory. IDE running or not. So that is why the function is called "RunningInProjectFolder" as this is more accurate.
I mainly use this under macOS, since the executable yourprojectfolder/yourapplication.app/Contents/macOS/yourapplication is actually linked to yourprojectfolder/yourapplication and ParamStr(0) is returning this (incorrect) location of the actual executable and not the link in the .app bundle.
So when pointing to resources in the .app bundle I need to use a different path.
For example resources in e yourprojectfolder/yourapplication.app/Contents/Resources would be accessed as "yourapplication.app/Contents/Resources" when running from the project folder.
However the path to those Resources will be "../Contents/Resources" when the application (.app bundle) is started outside of the project folder.
So here I use "RunningInProjectFolder" to set the proper path in my code.