Add an option or the ability to adjust the behaviour of Run (F9) from outside the "Run parameters"
- Lazarus/FPC Version: Lazarus 3.1 (rev lazarus_3_0) FPC 3.2.3 i386-win32-win32/win64
- Operating System: Windows 11
- CPU / Bitness: 64 bit.
What happens
Before Lazarus 3 whenever "Run" was invoked, the "Working directory" was, by default the same as the one for the "Target file name" field in Compiler Options -> Paths in Project options. New behavior requires a "Working directory" field to be specified in "Run parameters" if the target file name is on a different directory than the project file and requires simple access to files in the same directory. (Say... a "bin" subfolder).
While in principle the change sounds like a good idea, in practice it is not: setting absolute paths in the "Target file name" field would make compiling downloaded sources and finding the resulting binary troublesome for someone obtaining the source via, for instance, SVN. Simple programs can get by, no problem; but whenever data files are involved... issues begin.
It is true "Run parameters" can be saved in the .lpi or the .lps file and setting "Path(
(OutputFile))" would be an effective solution; but some other options are just debugging "one shots" meant for the .lps and not someone donwloading the source, just wanting to compile it and run it; if the option to save the run parameters is changed to "Project Session"... they are removed from the .lpi (Why?). That makes the whole system quite unusable and rather frustrating.
Not having a mess, that includes even the compiled binary and data files, in the "base" folder for the project comes down to personal preference, indeed; but I suspect a lot of people are not fond of it, being programmers and all. Not to mention the unnecessary work to update every... single... project that uses a subfolder in the "base" project directory with the binary and data. This used to work mostly fine (except, apparently, when dealing with "Host application").
What did you expect
Martin_fr mentioned in the forum a willingness to add an option or preset. What makes the most sense, to me, is adding an option for "Default work folder" (or whatever wording to that effect) to the "Paths" page in the Compiler Options for the Project options; that default should be used if the "Working directory" in the "Run parameters" is empty (I believe, also, that "Run parameters" is not the best place to find the "Working directory" text field as things are now; but that's a different issue).
Steps to reproduce
Make a simple text file that contains whatever you want. Save the text file in a "bin" subfolder off the project's "base" folder. Write a simple program that tries to find it (FileExists works); make the program throw a run time error if the file is not found. Set the "Target File Name" to bin/somefilename. Try to debug it under Lazarus. Lazarus will report the run time error. I provide a simple sample project that does just what I describe above.workdir.zip