Mega Code Archive

 
Categories / Delphi / Files
 

How to get your programs directory

Title: How to get your programs directory procedure TForm1.Button1Click(Sender: TObject); var sExePath: string; begin sExePath := ExtractFilePath(Application.ExeName) ShowMessage(sExePath); end; { To get your program's Exe-Name: } procedure TForm1.Button2Click(Sender: TObject); var sExeName: string; begin sExeName := ExtractFileName(Application.ExeName); ShowMessage(sExeName); end; { Instead of Application.ExeName you can also use Paramstr(0) } { If you are working on a DLL and are interested in the filename of the DLL rather than the filename of the application, then you can use this function: } function GetModuleName: string; var szFileName: array[0..MAX_PATH] of Char; begin FillChar(szFileName, SizeOf(szFileName), #0); GetModuleFileName(hInstance, szFileName, MAX_PATH); Result := szFileName; end;