[SOLVED][MACOS] Loading file with relative path problem lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- BeanzMaster · 2020-08-13 20:54 Hi to all i have a little problem, and can say how to solve it I have several applications that I compile under different OS (Windows, Linux and Mac) In order not to duplicate my resource files, I have a folder structure like below -Root    - Demos       - Resources         - images         - sounds       - App1          - Bin             - Windows                - compileMode                   - cpu/App1.exe             - Linux                - compileMode                   - cpu/App1             - MacOS                - compileMode                   - cpu/App1.app       - App2          - Bin             - Windows                - compileMode                   - cpu/App2.exe             - Linux                - compileMode                   - cpu/App2             - MacOS                - compileMode                   - cpu/App2.app        - etc... In my code i have Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FTextureBuf fer.LoadFromFile('../../../../../media/images/texturemaphq.tga'); It work under Windows and Linux but not on MacOS Note i say the folder of MacOS app is in "Content/MacOS" My problem is how to accessing to the Resources folder from the current folder of the executable ? I tried by adding "../" twice but it's not work. The problem is that the folder is in the back. If it will be a subfolder I wouldn't have any problems Thanks in advance ---------------------------------------------------------------------- jwdietrich · 2020-08-13 21:06 You might want to check for the working directory with GetCurrentDir. ---------------------------------------------------------------------- BeanzMaster · 2020-08-13 21:30 Quote from: jwdietrich on August 13, 2020, 11:06:01 pmYou might want to check for the working directory with GetCurrentDir. Get the current dir don't solve the problem. Like i said resources folder is not a subfolder. Under Linux and Windows we get directly the right folder but not under MacOS. I think i'll must do a special function to get the absolute path. ---------------------------------------------------------------------- winni · 2020-08-13 22:00 Hi! start with fname := application.exename; Then start counting from the end the number of slashes plus one. Then you got the offset were to delete the right part of fname. Now you got the absolute path. That should solve it. On a normal system. I don't know nothing about the Mac. Winni ---------------------------------------------------------------------- trev · 2020-08-14 01:09 If the issue is locating the macOS application bundle's resources directory, then see the Wiki Locating the macOS application resources directory. (It might have been better to post in the Forum » Programming » Operating Systems » macOS / Mac OS X forum as I nearly missed this post.) ---------------------------------------------------------------------- BeanzMaster · 2020-08-14 08:18 Hi Quote from: trev on August 14, 2020, 03:09:41 amIf the issue is locating the macOS application bundle's resources directory, then see the Wiki Locating the macOS application resources directory. I say that and  is  exactly what i won't do because i have more than 20 applications demos and also because i don't provide any executable only source code Quote from: trev on August 14, 2020, 03:09:41 am(It might have been better to post in the Forum » Programming » Operating Systems » macOS / Mac OS X forum as I nearly missed this post.) No problem i don't take care. It will be for the next problem Quote from: winni on August 14, 2020, 12:00:18 amstart with fname := application.exename; Then start counting from the end the number of slashes plus one. Then you got the offset were to delete the right part of fname. Now you got the absolute path. That should solve it. That's exactly what i was thinking  Cheers ---------------------------------------------------------------------- BeanzMaster · 2020-08-14 10:18 If someone need something similar i'm doing like this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetApplicationPath : string;begin  {$IFDEF DARWIN}  result := Copy(Application.ExeName, 1, Pos(ApplicationName + '.app', Application.ExeName) - 1);  {$ELSE}  Result :=  Application.Location;  {$ENDIF}  Result :=  IncludeTrailingPathDelimiter(Result);end;  function GetAbsolutePathFromApp(SearchPath : String) : String;Var  RelTag : String;  AppPath : String;  TmpRelPath : String;  cnt,i : Integer;begin  RelTag := '..' + pathdelim;  AppPath := GetApplicationPath;  TmpRelPath := FixPathDelimiter(SearchPath);  if (Pos(RelTag, TmpRelPath) > 0) then  begin    cnt := 0;    while (Pos(RelTag, TmpRelPath) > 0) do    begin      TmpRelPath := Copy(TmpRelPath,4,Length(TmpRelPath));      inc(cnt);    end;     if cnt > 0 then    begin      for i:= 1 to cnt do      begin        AppPath := ExpandFileName(IncludeTrailingPathDelimiter(AppPath) + '..');      end;    end;     Result := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(AppPath) + TmpRelPath);  end  else  begin    Result := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(AppPath) + SearchPath);  end;end;