Recent

Author Topic: Problem with TFileAssociation Component  (Read 1514 times)

simone

  • Sr. Member
  • ****
  • Posts: 356
Problem with TFileAssociation Component
« on: March 30, 2019, 07:16:17 pm »
I'm trying to use TFileAssociation component, but it seems doesn't work.

This is a snippet of the code. The whole program is attached.

Any suggestione? Thanks in advance.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2.   var
  3.     Assoc: TFileAssociation;
  4.     CurDir : string;
  5.   begin
  6.     Assoc:=TFileAssociation.Create(self);
  7.     with Assoc do
  8.       begin
  9.         CurDir:=ExtractFilePath(Application.ExeName);
  10.         ApplicationName:='MyGraphEditor';
  11.         ApplicationDescription:='My Graph Editor';
  12.         Extension:='.flw';
  13.         ExtensionName:='My Graph Editor';
  14.         ActionIcon:='"'+CurDir+'project.ico"';
  15.         Action:='"'+CurDir+'project.exe" "%1"';
  16.         ActionName:='Open';
  17.         ActionIcon:='"'+CurDir+'project.ico"';
  18.         RegisterForAllUsers:=True;
  19.         if Execute then
  20.           begin
  21.             ShowMessage('ok');
  22.             ClearIconCache;
  23.           end;
  24.         Free;
  25.       end;
  26.   end;
Microsoft Windows 10 64 bit - Lazarus 2.0.10

lainz

  • Hero Member
  • *****
  • Posts: 3711
  • Leandro Diaz
Re: Problem with TFileAssociation Component
« Reply #1 on: March 30, 2019, 09:42:43 pm »
You're running the application as administrator?

Register for all users needs admin permission.

simone

  • Sr. Member
  • ****
  • Posts: 356
Re: Problem with TFileAssociation Component
« Reply #2 on: March 30, 2019, 10:52:00 pm »
Yes, I'm working as administrator on a pc with Windows 10 64bits. In this situation, 'Assoc.Execute' returns 'False'. However if I start the program using the 'run as administrator' popup option, 'Assoc.Execute' gives 'True', but in this case, is changed 'ExtensionName' only.
Microsoft Windows 10 64 bit - Lazarus 2.0.10

lainz

  • Hero Member
  • *****
  • Posts: 3711
  • Leandro Diaz
Re: Problem with TFileAssociation Component
« Reply #3 on: March 30, 2019, 11:38:06 pm »
This was coded on Windows 7 days. I think windows 10 don't allow to change file extension entirely by registry entries or something else changed. For example when you install an app that replaces file extension windows prompt you when you go to open it wich app you want to use.

simone

  • Sr. Member
  • ****
  • Posts: 356
Re: Problem with TFileAssociation Component
« Reply #4 on: March 30, 2019, 11:45:59 pm »
Thanks Lainz. Your explanation is plausible. As soon as possible I will test my code on Windows 7 to see what happens.
Microsoft Windows 10 64 bit - Lazarus 2.0.10

lainz

  • Hero Member
  • *****
  • Posts: 3711
  • Leandro Diaz
Re: Problem with TFileAssociation Component
« Reply #5 on: March 31, 2019, 01:09:48 am »
Another thing I remember is that the folder must be accessible for all users like program files or public documents.

Edit: And another is that your .exe must have Project Information enabled and values set, since Windows read the application name from there.

Another thing is that the icon is named "project1.ico" not "project.ico", I renamed the icon to fit the code. As well the exe name was wrong, "project1.exe" I renamed it to "project.exe".

I put the exe and the icon in public documents, so it's accessible by all users. (Program files will be OK too).

See attached screenshot, the app extension is correctly registered. As well in the second screenshot you can see is registered in "Default Programs" setting in Control Panel.
« Last Edit: March 31, 2019, 03:19:07 am by Lainz »

simone

  • Sr. Member
  • ****
  • Posts: 356
Re: Problem with TFileAssociation Component
« Reply #6 on: March 31, 2019, 12:21:00 pm »
Thanks Lainz, you are really kind. The errors in file names in the code I published are due to adaptation from my original program. Now on my pc all works as expected. The only drawback is that the program does not work if I run it simply by double click on the exe icon, even if I have an account with admin privileges, but it requires to be started with 'run as administrator' option of system popup menu. I presume this depends on Windows, not on yours nice component.

A last question: What is the difference between ActionIcon and ExtensionIcon?     
Microsoft Windows 10 64 bit - Lazarus 2.0.10

lainz

  • Hero Member
  • *****
  • Posts: 3711
  • Leandro Diaz
Re: Problem with TFileAssociation Component
« Reply #7 on: March 31, 2019, 03:54:44 pm »
ActionIcon is the icon on the right click menu, the icon at the left of 'Open'.

ExtensionIcon is the icon of the file extension.

 

TinyPortal © 2005-2018