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(???);
Grayl1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ms99Connect With a Mentor Commented:
Sorry:

it's not

memo1.loadFromFile(paramstr(1));

but

memo1.lines.loadFromFile(paramstr(1));

0
 
RheingoldCommented:
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
0
 
Grayl1Author Commented:
Rheingold...

Yes, U has understood me right.
I'm a bit new to Delphi so if you could give me an example...
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Grayl1Author Commented:
Rheingold...

Yes, U has understood me right.
I'm a bit new to Delphi so if you could give me an example...
0
 
ms99Commented:
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.
0
 
intheCommented:
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;
0
 
intheCommented:
oops shouldve pushed refresh first ;-)
0
 
bryan7Commented:
listenning
0
 
Grayl1Author Commented:
It works ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.