Windows file association allows you to specify what application recognizes a particular extension. For example, if on your desktop there is a file named
MYSTORY.DOC and you have Microsoft Word installed, Windows will launch MS-Word. Word then receives the name of the document selected and opens it.
In Windows 95/98/NT these associations are stored in the registry under the key
HKEY_CLASSES_ROOT. There are two parts to the association, first a key is created with the name of the file extension (i.e. .doc). The other part is a key that the extension points to that contains all the information about the icon to display for the extension and the command to execute when the file is launched.
For example, the .TXT extension is associated with NOTEPAD.EXE when Windows 95/98/NT is first installed. To accomplish this, there is a key named
.txt, which has a description of
txtfile. There is also a key named
txtfile. Under the second key there are two sub-keys of importance,
DefaultIcon and
Shell.
DefaultIcon indicates to Windows where the file is located that contains the icon to be displayed when the extension is represented either on the desktop or in Explorer. The default string should be the path and filename of the .EXE or .DLL or .ICO that contains the icon followed by a comma and then a number indicating the number of the icon in the file to use (i.e.
C:\Windows\Notepad.exe, 0).
Shell identifies what command(s) to add to the context-menu associated with the extensions icon. The most common is Open, but there can be others like Print. Any operation other than Open has to be handled by the associated application via command-line parameters. In the case of Open, there is a key under
Shell named
Open. Under
Open is another key named
Command.
Command is where the actual command is stored. This should contain the command line to be executed (i.e. C:\Windows\Notepad.exe %1).
So, how does the component help
Messing with one's registry is not a good thing to do, especially if you are unfamiliar with it. There is vital information stored in the registry that if manipulated can render your computer inoperatable.
So if you need the ability to create file associations, TMILAssociate is just what you need. This component provides the ability to identify an application to associate an extension with and then allows you to associate extensions with the application.
If you have used Windows 95/98/NT for a while, you have probably noticed that if you right-click on an icon you get a popup-menu. This is referred to as the Explorer context-menu. If there is a file association with the selected icon, the available commands (Open, Print, etc.) will be listed at the beginning of the menu. If Quick View has been enabled, there will be a menu item listed next to allow you to view the file with Quick View. TMILAssociate allows you to turn on Quick View for your associations, when it is turned on then the Quick View option appears in the Explorer context-menu for that extension.
Another thing you may have noticed if you've used Windows 95/98/NT is that when you right-click on the desktop (without selecting an icon) you will receive a different shell context-menu. One of the options in this menu is
New, and when you select it another menu opens listing various document types (i.e. Text Document, Wave Sound, etc.) TMILAssociate also allows you to turn on the option of having your extension appear in this list as well.
The following code will register the current application for association and then associate the .LOG extension with it. Again, if there is already an association for .LOG, it will be stored so that if later you remove the association (maybe in you un-install process) the original .LOG association can be restored.
procedure TForm1.FormCreate(Sender: TObject);
begin
MILAssociate1.KeyName := Application.Title;
MILAssociate1.PathToApp := Application.ExeName;
MILAssociate1.IconPath := ParamStr(0);
MILAssociate1.Icon := 0;
MILAssociate1.ShellCmd := 'Open';
MILAssociate1.Shell := Application.ExeName + ' "%1"';
MILAssociate1.TypeName := Application.Title + ' document';
MILAssociate1.ShowInNew := False;
MILAssociate1.QuickView := True;
MILAssociate1.RegisterApp;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MILAssociate1.Associate('.LOG');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
MILAssociate1.UnAssociate('.LOG');
end;
Return to the top