Recent

Author Topic: TFileAssociation component  (Read 7928 times)

lainz

  • Guest
TFileAssociation component
« on: February 15, 2013, 11:42:13 pm »
TFileAssociation component

Wiki: http://wiki.lazarus.freepascal.org/FileAssociation

With this component you can easily register file associations for all Windows versions. This includes Windows Vista/7/8 Default Programs feature.

Test program 'Lazarus File Association'. This is for all the people using Lazarus SVN  ;)
http://sourceforge.net/projects/lainz007/files/FileAssoc/lazfileassoc_win32.7z/download

See attached screenshot.

Download package:
http://sourceforge.net/projects/lainz007/files/FileAssoc/fileassoc_package.7z/download

Installation:
- Install like anypackage. The component is under the "System" tab.

PD: you can install it or just use the FileAssociation.pas file.

Usage:
- See the 'test' folder.
« Last Edit: February 16, 2013, 07:18:18 pm by lainz »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: TFileAssociation component
« Reply #1 on: February 16, 2013, 09:02:50 am »
Please read this wiki page and create a page for the component, if you didn't do it yet. That is all you have to do for adding to Lazarus-CCR. If you wish I can upload it the SF site of Lazarus-CCR too.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TFileAssociation component
« Reply #2 on: February 16, 2013, 09:08:43 am »
Great, Lainz, thanks a lot!
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

lainz

  • Guest
Re: TFileAssociation component
« Reply #3 on: February 16, 2013, 07:03:47 pm »
Please read this wiki page and create a page for the component, if you didn't do it yet. That is all you have to do for adding to Lazarus-CCR. If you wish I can upload it the SF site of Lazarus-CCR too.
Ok I'll create the page.
Edit: here it is http://wiki.lazarus.freepascal.org/FileAssociation

Great, Lainz, thanks a lot!

Hope you like it =)
« Last Edit: February 16, 2013, 07:21:02 pm by lainz »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TFileAssociation component
« Reply #4 on: February 17, 2013, 09:45:33 am »
@Lainz: I fixed some typos etc on the page.

I noticed this:
Quote
LGPL (The same as Lazarus).
Are you sure you don't want to change that to:
Quote
Modified LGPL (The same as Lazarus).
?
LCL=Modified LGPL
IDE=GPL

Thanks,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

lainz

  • Guest
Re: TFileAssociation component
« Reply #5 on: February 17, 2013, 12:59:49 pm »
Thanks. Ok i've changed it to Modified LGPL.

lainz

  • Hero Member
  • *****
  • Posts: 3398
    • Lainz
Re: TFileAssociation component
« Reply #6 on: April 04, 2014, 07:51:05 pm »
Hi, I've updated TFileAssociation, now it consumes less memory and it has few options. It's all OOP now.

http://wiki.lazarus.freepascal.org/FileAssociation

Also I've tested it better and you need to compile both 32 and 64 bit executable depending on windows version.

LovelyA72

  • Newbie
  • Posts: 2
  • 私はとても好きですPascal!
Re: TFileAssociation component
« Reply #7 on: January 10, 2019, 08:36:29 am »
The lazfileassoc_win32.7z file no longer exists. Can you please re-upload it or include it as an example in the package?

Thank you!

GetMem

  • Hero Member
  • *****
  • Posts: 3541
Re: TFileAssociation component
« Reply #8 on: January 10, 2019, 08:39:06 am »
@LovelyA72
You can find it in OPM.

LovelyA72

  • Newbie
  • Posts: 2
  • 私はとても好きですPascal!
Re: TFileAssociation component
« Reply #9 on: January 10, 2019, 08:44:29 am »
@LovelyA72
You can find it in OPM.

I already installed it from OPM. But there's no example project included.

Maybe I'll just build a new program to test it... Thank you for your reply!

GetMem

  • Hero Member
  • *****
  • Posts: 3541
Re: TFileAssociation component
« Reply #10 on: January 10, 2019, 08:52:42 am »
Maybe the example at the following page helps: http://wiki.lazarus.freepascal.org/FileAssociation

maurobio

  • Full Member
  • ***
  • Posts: 110
Re: TFileAssociation component
« Reply #11 on: December 15, 2019, 09:57:01 pm »
@lainz,

Thanks a lot for this component, but could another example be provided, showing how an application can  effectively open an associated file when the user clicks upon the file icon? I presume some code for treating the  program execution parameter need to be write, but this is not clear from the available documentation for the component.

Thanks in advance for any assistance you can provide.

Best wishes,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 1.9.3/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 19 ("Tessa"), Windows XP SP3, Windows 7 Professional, Windows 10 Home

lainz

  • Hero Member
  • *****
  • Posts: 3398
    • Lainz
Re: TFileAssociation component
« Reply #12 on: December 15, 2019, 11:03:11 pm »
@lainz,

Thanks a lot for this component, but could another example be provided, showing how an application can  effectively open an associated file when the user clicks upon the file icon? I presume some code for treating the  program execution parameter need to be write, but this is not clear from the available documentation for the component.

Thanks in advance for any assistance you can provide.

Best wishes,

For example if the associated file is a text file you can do:

Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   s: String;
  4. begin
  5. // if there are parameters
  6.   if ParamCount > 0 then
  7.   begin
  8. // load the first parameter
  9.     s := ParamStr(1);
  10.  
  11. // if is a .txt file
  12.     if ExtractFileExt(s) = '.txt' then
  13.     begin
  14. // load the .txt file into a memo
  15.       Memo1.Lines.LoadFromFile(s);
  16.     end;
  17.   end;
  18. end;    

maurobio

  • Full Member
  • ***
  • Posts: 110
Re: TFileAssociation component
« Reply #13 on: December 15, 2019, 11:30:17 pm »
@lainz,

Thanks for the fast reply.

Unfortunately, it still does not work. When I click on an associated file, Windows Explorer asks for the application to be used to open it.

I have the Action property set to '"fde.exe" "%1"', where fde.exe is my application executable. I suppose this line, along with the code you provided, should do the trick, but it does not. In fact, the test of ParamCount > 0 returns False!

Any hints?

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 1.9.3/2.0.4 - FPC 3.0.4 on GNU/Linux Mint 19 ("Tessa"), Windows XP SP3, Windows 7 Professional, Windows 10 Home

lainz

  • Hero Member
  • *****
  • Posts: 3398
    • Lainz
Re: TFileAssociation component
« Reply #14 on: December 15, 2019, 11:34:24 pm »
Unfortunately, it still does not work. When I click on an associated file, Windows Explorer asks for the application to be used to open it.

I have the Action property set to '"fde.exe" "%1"', where fde.exe is my application executable. I suppose this line, along with the code you provided, should do the trick, but it does not. In fact, the test of ParamCount > 0 returns False!

Any hints?

Best regards,

Hi, "fde.exe" "%1" this is wrong.

It must be like:
'"C:\lazarus\lazarus.exe" "%1"'

It requires a full path.

You can use ParamStr(0) to get your full .exe path. I will add that to the wiki too.

Added like this:
"// full path required, you can use ParamStr(0) to get the path with the .exe name included. The path must be inside quotes if it has whitespace."

Edit, also take into account this I've added:

  // 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;
« Last Edit: December 15, 2019, 11:54:19 pm by lainz »