Recent

Author Topic: [Solved] File missing when running compiled project  (Read 1671 times)

Serge58

  • New Member
  • *
  • Posts: 37
[Solved] File missing when running compiled project
« on: February 21, 2018, 05:49:02 pm »
Hello,

I am doing a project and store variables in a text file.
When I run it from Lazarus it works fine.
However, when I want to run it directly form the application by clicking on the app inside the directory,  it says that it is unable to open this text file.

The text file is it the root directory where Lazarus compiles the project.

What am I not understanding?

Thanks,



« Last Edit: February 26, 2018, 03:44:07 pm by Serge58 »

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: File missing when running compiled project
« Reply #1 on: February 21, 2018, 06:02:09 pm »
It is important to understand the operating system you're using. I'm assuming you're using a POSIX-like OS (i.e. Linux) as in these systems the working directory (i.e. the default directory where applications look for files) isn't the directory where the executable is (as in Windows OS).

On POSIX the working directory is the one from the application was invoked from.  Lazarus invokes the compiled from the same directory where the compiled application is saved because that is the last working directory for Lazarus.

If your application should load files to get static data (not working data, but other stuff as configurations, options, extensions, translations, etc.) you should tell it from where to get it (i.e. the appropriate data directory).  Read this wiki for a brief description of how standard POSIX directories are defined and used.

Note that Windows also has its own directory hierarchy and you should use it correctly as well. Here you have a brief description for Windows 10.
« Last Edit: February 21, 2018, 06:11:47 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Serge58

  • New Member
  • *
  • Posts: 37
Re: File missing when running compiled project
« Reply #2 on: February 21, 2018, 06:23:34 pm »
Thanks for aligning me on the right path.
I am on Mac and to me the file system is very complicated.
Thanks again,

I found the following which works perfectly:

pos:= AnsiPos('myapp.app',Application.Location);
mypath :=AnsiLeftStr(Application.Location, pos-1);


Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: File missing when running compiled project
« Reply #3 on: February 22, 2018, 11:33:29 am »
AFAIK modern MacOS is BSD based, so it is almost POSIX but with some custom changes (you know, it is Apple so it doesn't want to be so compatible ;)).
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

 

TinyPortal © 2005-2018