Mega Code Archive

 
Categories / Delphi / Files
 

How to get the filename, if a file is opened with your application

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} // open an file with the project to test it. // if a file is available an message will appear. procedure TForm1.FormCreate(Sender: TObject); var S : string; begin // Get commandline S := CmdLine; // Remove the application path from CmdLine, +3 = "" and space Delete(S,1,length(Application.ExeName)+3); if length(S) > 0 then begin // Found filename Showmessage('Found File : ' + S); end; end; end.