Hi
On this
wiki page, there is a piece of code which looks wrong.
1) The name is not appropriate
2) A begin is in the wrong place
3) it refers to a TConfigurations class, not defined here
4) BundleResourcesDirectory is probably a property of this class, but unknown here.
5) The Unix and not Darwin part is certainly wrong with "myapp" as a constant.
I suggest the code below working on Windows, Linux and OSX (10.6 only):
uses
{$ifdef Darwin}
MacOSAll,
{$endif}
SysUtils;
function GetAppExecPath : string;
{$ifdef Darwin}
var
pathRef: CFURLRef;
pathCFStr: CFStringRef;
pathStr: shortstring;
{$endif}
begin
{$ifdef Darwin}
pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
CFRelease(pathRef);
CFRelease(pathCFStr);
Result := pathStr + DirectorySeparator;
{$else} // Win32 or Linux
Result := ExtractFilePath(Application.EXEName);
{$endif}
end;
If someone knows how to deal with Unix and not Darwin, and can test it, he his welcome, but otherwise I think it is better to remove this part.
Unless someone can see something wrong, I could submit this in the bugtracker, to make a new more portable function in a next FPC or Lazarus version.
Regards