Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Delphi - How to associate my application with a file-extension
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
October 22, 2013 9:50 AM
The following procedure helps you set your application as the default file handler for a particular file extension:
procedure RegisterFileType(ExtName:String; AppName:String);
var reg:TRegistry;
begin
reg := TRegistry.Create;
try with reg do
begin
RootKey:=HKEY_CLASSES_ROOT;
OpenKey('.' + ExtName, True);
WriteString('', ExtName + 'file');
CloseKey;
CreateKey(ExtName + 'file');
OpenKey(ExtName + 'fileDefaultIcon', True);
WriteString('', AppName + ',0');
CloseKey;
OpenKey(ExtName + 'fileshellopencommand', True);
WriteString('',AppName+' "%1"');
CloseKey;
end;
finally
reg.Free;
end;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil) ;
end;