[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

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(???);
0
Grayl1
Asked:
Grayl1
  • 3
  • 2
  • 2
  • +2
1 Solution
 
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
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
ms99Commented:
Sorry:

it's not

memo1.loadFromFile(paramstr(1));

but

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

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now