Link to home
Start Free TrialLog in
Avatar of Grayl1
Grayl1

asked on

open a txt witn an app

How to open for example a txt with an app in Delphi? I mean, you should right click with shift pressed on the txt and then choose open with... and then select my app in the list.

What source should this app contain?
Memo1.Lines.LoadFromFile(???);
Avatar of Rheingold
Rheingold

Hi, if I understand you correct you want your app to be able to process text files that are loaded through the "open with" option of the Win Explorer? If so, you have to handle the Command Line the app gets. The API function is GetCommandLine. It should be something similar in Delphi. The first part of the string this API returns is the path and the filename of your EXE and the second part is path and filename of the TXT file. Just write a quick algo that extracts the second part. Send this part to LoadFromFile then.

Regards
Avatar of Grayl1

ASKER

Rheingold...

Yes, U has understood me right.
I'm a bit new to Delphi so if you could give me an example...
Avatar of Grayl1

ASKER

Rheingold...

Yes, U has understood me right.
I'm a bit new to Delphi so if you could give me an example...
To understand what Rheingolg means just drop a label1 in your application and do this:

label1.caption := '>' + getCommandLine + '<';

Double click on a txt file and you will see something like:

>c:\project1.exe c:\myfile.txt<

Another way is:

memo1.loadFromFile(paramstr(1));

in order to load the file.
ASKER CERTIFIED SOLUTION
Avatar of ms99
ms99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,
GetCommandLine returns the commandline used to start program  ie: project1.exe/ns
example:
edit1.text:=strpas(GetCommandLine);

what your after for this is paramstr() like below:

procedure TForm1.FormCreate(Sender: TObject);
begin
try
memo1.lines.loadfromfile(ParamStr(1))
except
end;
end;
oops shouldve pushed refresh first ;-)
listenning
Avatar of Grayl1

ASKER

It works ;-)