Recent

Author Topic: [SOLVED] GetResourcesPath() in the wiki  (Read 2019 times)

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
[SOLVED] GetResourcesPath() in the wiki
« on: July 19, 2016, 03:35:25 pm »
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):

Code: Pascal  [Select][+][-]
  1. uses
  2. {$ifdef Darwin}
  3.   MacOSAll,
  4. {$endif}
  5.   SysUtils;

Code: Pascal  [Select][+][-]
  1. function GetAppExecPath : string;
  2.  
  3. {$ifdef Darwin}
  4. var
  5.   pathRef: CFURLRef;
  6.   pathCFStr: CFStringRef;
  7.   pathStr: shortstring;
  8. {$endif}
  9. begin
  10. {$ifdef Darwin}
  11.   pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
  12.   pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
  13.   CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
  14.   CFRelease(pathRef);
  15.   CFRelease(pathCFStr);
  16.   Result := pathStr + DirectorySeparator;
  17. {$else} // Win32 or Linux
  18.   Result := ExtractFilePath(Application.EXEName);
  19. {$endif}
  20. end;
  21.  

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

« Last Edit: July 19, 2016, 04:26:53 pm by tintinux »
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: GetResourcesPath() in the wiki
« Reply #1 on: July 19, 2016, 03:55:31 pm »
In FileUtil there is also ProgramDirectory function. Should be used instead of ExtractFilePath(Application.EXEName);

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: GetResourcesPath() in the wiki
« Reply #2 on: July 19, 2016, 04:26:31 pm »
Ahh, thanks for the information !

It works on OS/X too, the problem is solved for me, and the whole paragraph should be removed from the Wiki

Regards

Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

 

TinyPortal © 2005-2018