Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Open a delphi app from its associated file


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Apr 17, 2017 9:01 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Francisco Peris

Posts: 77
Registered: 1/5/15
Open a delphi app from its associated file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 17, 2017 1:34 AM
Hi everybody:

I am learning how to modify Windows registry to associate a file extension to a windows application.

The next step is that the user double clicks on one of the associates files and the app starts opening that file.

I cannot find the way of doing it. How can I know when my delphi app starts the name of the file, and that a file has been double clicked?

Any ideas?
Antonio Estevez

Posts: 600
Registered: 4/12/00
Re: Open a delphi app from its associated file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 17, 2017 2:25 AM   in response to: Francisco Peris in response to: Francisco Peris
El 17/04/2017 a las 10:34, Francisco Peris escribió:
Hi everybody:

I am learning how to modify Windows registry to associate a file extension to a windows application.

The next step is that the user double clicks on one of the associates files and the app starts opening that file.

I cannot find the way of doing it. How can I know when my delphi app starts the name of the file, and that a file has been double clicked?

Any ideas?

You can get the full file name from the command line parameters. Normally it's the first parameter:

var
    FileName: String;
...
   if ParamCount >= 1 then
   begin
     FileName := ParamStr(1);
   end;
...
Remy Lebeau (Te...


Posts: 8,716
Registered: 12/23/01
Re: Open a delphi app from its associated file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 17, 2017 9:01 AM   in response to: Francisco Peris in response to: Francisco Peris
Francisco wrote:

The next step is that the user double clicks on one of the associates
files and the app starts opening that file.

I cannot find the way of doing it. How can I know when my delphi app
starts the name of the file, and that a file has been double clicked?

All you have to do is check the command-line parameters that are passed to
your app when it starts running. Look at the RTL's ParamCount() and ParamStr()
functions for that purpose.

For example, if you set up your Registry key like this:

HKEY_CLASSES_ROOT\.myext
@="MyExtFile"
 
HKEY_CLASSES_ROOT\MyExtFile\Shell\open\command
@=""<path to>\myapp.exe" "%1""


Then, if your app is run by double-clicking on a ".myext" file, ParamStr(1)
will return the filename that was clicked on. Otherwise, ParamStr(1) will
return a blank string.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02