Recent

Author Topic: GetCurrentDir on MacOS  (Read 571 times)

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 287
GetCurrentDir on MacOS
« on: November 02, 2022, 10:37:24 am »
If I set the working directory to {folder} in the Run Parameters dialog, shouldn't that {folder} be what I get back from SysUtils.GetCurrentDir ?

Because GetCurrentDir is returning / not the folder I set. Is that expected?

Details:
* Mac M1 Max / Monterey 12.5
* Lazarus 2.2.5 (rev lazarus_2_2_4-3-g564e1e8244) FPC 3.2.2 aarch64-darwin-cocoa
« Last Edit: November 02, 2022, 10:53:47 am by Grahame Grieve »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1040
Re: GetCurrentDir on MacOS
« Reply #1 on: November 02, 2022, 08:32:55 pm »
The system always forces the working directory of GUI applications to the root directory, probably to discourage you from trying to use it. You cannot/must not rely on it on macOS for GUI applications.

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 287
Re: GetCurrentDir on MacOS
« Reply #2 on: November 02, 2022, 08:44:43 pm »
oh. thanks. Where is that documented? Should the dialog box disable the working directory in that case?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1040
Re: GetCurrentDir on MacOS
« Reply #3 on: November 02, 2022, 08:48:55 pm »
oh. thanks. Where is that documented?
It's more that Apple doesn't mention using the working directory as a correct way to access any files: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html

Quote
Should the dialog box disable the working directory in that case?
It should still work fine for command line programs.

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 287
Re: GetCurrentDir on MacOS
« Reply #4 on: November 02, 2022, 09:30:57 pm »
Lazarus can know which is which, right?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1040
Re: GetCurrentDir on MacOS
« Reply #5 on: November 02, 2022, 09:33:18 pm »
I don't know if it keeps track of that in the project file. There's also nothing preventing you from creating a GUI application using the template of a command line application (with or without the LCL).

 

TinyPortal © 2005-2018