Have you ever wondered how installation programs are able to associate a file extension with a program? Or how when you double click on a MS Word file, Microsoft Word automatically starts up and loads that particular file? Well, in this article I will explain how it is done.
Creating an Associator - How to enable the application to load the file that has been clicked (Page 3 of 4 )
When an application starts, it has certain variables at its disposal. One of them is ParamStr();. "ParamStr(n)" is a global variable that contains various pieces of information in the following order:
ParamStr(0) = The current application name and path
ParamStr(1) = The file name that the user clicked on in Explorer or passed through the command line.
We are interested in ParamStr(1) since it will contain the parameters that the user passed to the application. So to check whether this variable contains something:
Var Applicationname,Avariable:string; begin ApplicationName := ParamStr(0); If ParamCount = 1 then AVariable := ParamStr(1); ... //Use AVariable for whatever purpose you want to..... End;
Make sure to add the above code to your applications' OnCreate event, and it will be able to start if a file that it is associated to is passed.