Author Topic: ProgramDirectoryWithBundle  (Read 740 times)


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 924
  • Former Delphi 1-7, 10.2 User
« on: June 20, 2019, 12:55:32 pm »
I was browsing FileUtil.pas and noticed ProgramDirectory and ProgramDirectoryWithBundle. The latter one seemed just what I needed to eliminate application.location (rumoured to not work under macOS, but does in my somewhat limited experience to date).

Unfortunately, both ProgramDirectory and ProgramDirectoryWithBundle return the same directory, being the directory in which the program (app bundle) is located. Details of the latter are scant. Google gave me just 6 hits. One suggested ProgramDirectoryWithBundle would return the Resources directory in a bundle which is just what I want... if it worked. Even the path including the bundle name would work.

I tracked the source down to /Developer/lazarus/components/lazutils/ where I found this:

Code: Pascal  [Select][+][-]
  1. function ProgramDirectoryWithBundle: string;
  2. const
  3.   BundlePostFix='.app/Contents/MacOS';
  4. begin
  5.   Result:=ProgramDirectory;
  6.   if (RightStr(ChompPathDelim(Result),Length(BundlePostFix))=BundlePostFix) then
  7.     Result:=ExtractFilePath(LeftStr(Result,Length(Result)-Length(BundlePostFix)));
  8. end;

ProgramDirectory returns only the directory in which the app bundle (eg is located and not the where executable is located, but this code seems to assume it will return the full path to the executable in

For the time being, to locate my help book, I'm using the below which works:

Code: Pascal  [Select][+][-]
  1.   helpPath := application.location;
  2.   Delete(helpPath, Length(helpPath) - 6, 6);
  3.   OpenDocument(helpPath + 'Resources/');

Do I need to file a bug? If so, is this a Lazarus or an FPC bug?
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46864, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)


TinyPortal © 2005-2018