fileassociation dcFileAssociation example
dcFileAssociation component
Return to Introduction  Previous page  Next page
Following example demonstrates how to install and uninstall the file extension into the shell.
Let's say we'd like to install and uninstall the ".TEST" extension and point our executable as primary executable for this type …


procedure TForm1.InstallTestExtensionBtnClick(Sender: TObject);
begin
  dcFileAssociation.AccessMode := amReadWrite;
  dcFileAssociation.EXTENSION := 'test'
;
  dcFileAssociation.FileDescription := 'Test File'
;
  dcFileAssociation.ExecutableFile := Application.ExeName;
  dcFileAssociation.IconLocation := Application.ExeName;  
  dcFileAssociation.IconIndex := 1
;

{ ALTERNATIVELY, you can use InstallFileType method }
  dcFileAssociation.InstallFileType('.test', Application.ExeName, '%1''''testfile''My Test File', Application.ExeName, 1);
end;

procedure TForm1.UninstallTestExtensionBtnClick(Sender: TObject);
begin
  dcFileAssociation.UninstallFileType('test'
);
end;

{ how to catch the command line parameter and get the name of data file (in ParamStr(1)) }

procedure TForm1.FormCreate(Sender: TObject);
begin
  if ParamCount <> 0
 then
   ShowMessage('Started by "'
 + ParamStr(1) + '" file !');
end;