Creating an Associator - Continuing with the code
(Page 2 of 4 )
If everything is okay, create an instance of the registry object and set the rootkey as in the code below:
"reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT; // Set registry Key
reg.LazyWrite := false;"
Create a new registry key and add the extension, then add the program name and enable it to accept parameters as follows:
reg.OpenKey('.'+edExt.Text+'shellopencommand', true) then begin
reg.WriteString('', edappname.Text+' %1 ');
reg.CloseKey;
The next section of the procedure associates the extension with a icon, similar to the way MS Word associates all the ".doc" files with its icon. The first icon in an exe is usually the "defaulticon" or icon number "0." The code snippet below is responsible for associating the extension with the icon:
reg.OpenKey('.'+edExt.Text+'DefaultIcon', true);
{Use the first icon in the executable to display}
reg.WriteString('', edappname.Text+',0');
reg.CloseKey;
That's it. Now, after you've associated an extension with an application, the actual application also needs to be able to accept parameters.
Next: How to enable the application to load the file that has been clicked >>
More Delphi-Kylix Articles
More By Jacques Noah