I'm having trouble creating File Associations in Windows using the
FileAssoc package.
I installed the package from the Online Package Manager and first of all dropped two of the components onto my form.
I then set various parameters directly in the two components in the object inspector.
The only properties I couldn't figure out how to set in the Object inspector were
Action and the icon properties. I want these to use the directory that the application was installed in, so I set these programmatically with:
FileAssociation_tqr.Action:='"'+Application.ExeName+'" "%1"';
FileAssociation_tqr.ExtensionIcon:=Application.ExeName+',0';
I have an
if around the
FileAssociation_tqr.Execute and it seems it never succeeds.
I then changed the
ExtensionIcon to just be a static icon file in the application dirctory in case finding it in the .exe wasn't working, but no joy. he
.Execute still didn't return true.
So I changed tack completely and removed the two components from the form and set about creating them programmatically from scratch. I now have the following, but the
Execute still doesn't return true and the association is not made.
procedure TMainForm.createFileAssociations();
var
FileAssociation_tqr, FileAssociation_tqt: TFileAssociation;
begin
FileAssociation_tqr:= TFileAssociation.Create(self);
FileAssociation_tqr.ApplicationName:='My Application Name';
FileAssociation_tqr.ApplicationDescription:='My Application Description';
FileAssociation_tqr.Extension:='.tqr';
FileAssociation_tqr.ExtensionName:='My Application File';
FileAssociation_tqr.ExtensionIcon:=Application.ExeName+',0';
// FileAssociation_tqr.ExtensionIcon:=ExtractFilePath(Application.ExeName)+'icon.ico';
FileAssociation_tqr.Action:='"'+Application.ExeName+'" "%1"';
FileAssociation_tqr.ActionName:='Open';
FileAssociation_tqr.ActionIcon:=Application.ExeName+',0';
// FileAssociation_tqr.ActionIcon:=ExtractFilePath(Application.ExeName)+'icon.ico';
FileAssociation_tqr.RegisterForAllUsers:=true;
if FileAssociation_tqr.Execute then
begin
showMessage('.tqr assoc registered');
FileAssociation_tqr.ClearIconCache;
end
else
begin
showMessage('tqr failed');
end;
end;
Where am I going wrong? (I used
this as a guide.)
Thanks,
-FM