Difference between revisions of "FileAssociation"
From Lazarus wiki
Jump to navigationJump to search (Updated Download Link) |
(→Usage) |
||
Line 53: | Line 53: | ||
assoc.ActionIcon := '"C:\lazarus\images\mainicon.ico"'; | assoc.ActionIcon := '"C:\lazarus\images\mainicon.ico"'; | ||
− | + | // notice that using RegisterForAllUsers as True requires Administrator Privileges | |
+ | // if you want to run without privileges set it to false, but it will register for current user only | ||
+ | assoc.RegisterForAllUsers:=False; | ||
if assoc.Execute then | if assoc.Execute then | ||
begin | begin |
Revision as of 00:04, 16 December 2019
This article applies to Windows only.
See also: Multiplatform Programming Guide
│
English (en) │
français (fr) │
This article applies to Windows only.
See also: Multiplatform Programming Guide
TFileAssociation
Author: Lainz
Licence: Modified LGPL
Version: 1.0
Description: This unit registers file association for Windows.
Download
GitHub: https://github.com/lainz/FileAssociation
Usage
First install the package. You can drop the component TFileAssociation (FileAssoc unit) that gets installed in the System tab of the IDE.
...
uses
...
FileAssoc;//<-- add fileassociation unit here
type
...
{ private declarations }
assoc: TFileAssociation;
...
procedure TfrmMain.FormCreate(Sender: TObject);
begin
assoc := TFileAssociation.Create(Self);//<-- create like a regular component
end;
procedure TfrmMain.Button1Click(Sender: TObject);
begin
assoc.ApplicationName := 'Lazarus IDE';
assoc.ApplicationDescription := 'RAD for Free Pascal';
// you can change Extension and Action part for each extension you have
assoc.Extension := '.lpr';
assoc.ExtensionName := 'Lazarus Project';
assoc.ExtensionIcon := '"C:\lazarus\images\lprfile.ico"';
assoc.Action := '"C:\lazarus\lazarus.exe" "%1"';
assoc.ActionName := 'Open';
assoc.ActionIcon := '"C:\lazarus\images\mainicon.ico"';
// notice that using RegisterForAllUsers as True requires Administrator Privileges
// if you want to run without privileges set it to false, but it will register for current user only
assoc.RegisterForAllUsers:=False;
if assoc.Execute then
begin
ShowMessage('OK');
assoc.ClearIconCache; //<<-- rebuild icons
end;
end;
end.