Free Pascal
LAZARUS

Directory of the application

You get the full path to a program's executable with Paramstr(0).
Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(Paramstr(0));
end;
 

To get the directory (folder) of an application, you use ExtractFileDir(Paramstr(0)).
Example for saving a file to the directory of the program executable:

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Lines.SaveToFile(ExtractFileDir(Paramstr(0)) + '\Test.txt');
end