»  The Delphi Column 

  Where is the application's exe-file ?

When an external file is needed by your application (e.g. a txt-file, or an ini-file, or...) it's common practice to put the extra file(s) in the directory that contains the application's exe-file.

Say that after starting, the application should show the file testdata.txt in the memo component Memo1. Because at design time you don't know where testdata.txt will be located in the future, you write in your code:

Memo1.Lines.LoadFromFile(ExeDir + 'testdata.txt');

where ExeDir is the directory that contains the exe-file.

Code example

var
  ExeDir: string;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ExeDir := ExtractFilePath(ParamStr(0)); 
  Memo1.Lines.LoadFromFile(ExeDir + 'testdata.txt');
  // ...
  // and so on...
end; 

But this can give problems when you run your application in Delphi's IDE (Integrated Development Environment). Suppose that the project's source code files and the file testdata.txt are located in C:\DelphiTest, then you are likely to receive an error message as follows:

"Cannot open C:\DelphiTest\Win32\Debug\testdata.txt. The system cannot find the file specified."

That's because C:\DelphiTest\Win32\Debug is where the compiler generates the exe-file by default.

Solution: in Delphi's menu, select Project -> Options -> Building -> Delphi Compiler. You will see that the option "Output directory" is set to: .\$(Platform)\$(Config)
Replace this value with: .\


Database Tutorials  FAQ  Crash Course Delphi  Tips  Source Code  Downloads  Links

  Copyright 1999-2022 
DelphiLand