TMILAssociate v1.0.0
by Larry J. Rutledge

© Copyright 1998, Millennial Software, All Rights Reserved

  1. Component Description
  2. Properties and Events
  3. Installation
  4. Contacting the Author
  5. Disclaimer

Description

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


Properties and Events

Properties


Events


Return to the top


Installation

1. Unzip associat.zip to a temporary directory.
2. Copy MILAssociate.PAS, MILAssociate.DCR, MILAbout.PAS, and MILAbout.DFM to your components directory.
3. Install component file MILAssociate.PAS.
4. The new component should appear on a tab titled "Millennial".

Return to the top


Contacting the author

If you have questions, comments, bug reports, modifications, etc. please contact the author at:  Larry J. Rutledge


TMILFlashLabel is Freeware and can be used in freeware, shareware and commercial productions without my permission. You may modify the code, but please do not forget the documentation (and the credits).

You may not sell the component or the source without significant modifications.

Return to the top


Disclaimer

This software is provided "AS IS" without any warranty of any kind, either express or implied. The entire risk as to the quality and performance of the software is with you. Should the software prove defective, you assume the cost of all necessary servicing, repair or correction. In no event shall the author, copyright holder, or any other party who may redistribute the software be liable to you for damages, including any general, special, incidental, or consequental damages arising out of the use or inability to use the software (including, but not limited to, loss of data, data being rendered inaccurate, loss of business profits, loss of business information, business interruptions, loss sustained by you or third parties, or a failure of the software to operate with any other software) even if the author, copyright holder, or other party has been advised of the possibility of such damages.


For more information on various Delphi topics, visit the on-line newsletter "Delphi Gazette". You can find it at the following address:
http://www.prestwood.com/forums/delphi/sdug/newsletter/.


Return to the top
Last Updated: December 4, 1998