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


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

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

procedure TForm1.UninstallTestExtensionBtnClick(Sender: TObject);
begin
  acExtAssociation.UninstallExtension('.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;