Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File associations

Posted on 1998-01-06
10
Medium Priority
?
361 Views
Last Modified: 2010-04-04
Hi! How do I set file associations within code? I tried by setting registry values, but nothing happend.
0
Comment
Question by:fmichaud061597
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1355439
You mean to make the association permanent?
0
 

Author Comment

by:fmichaud061597
ID: 1355440
Yes, like many other programs do. For example, word97 documents use a specific icon in shell and when we double-click on them they open within word.
0
 

Accepted Solution

by:
Dippen earned 150 total points
ID: 1355441
This procedure creates a permanent file association for ".abc"-files, and it starts to work right away (no reboot required). To test it, make a copy of "Autoexec.bat" (or another textfile) and give the copy the extension ".abc". The example below will associate the ".abc"-extension with the 8th icon embedded in the standard "Defrag.exe" program supplied with W95.
   When you click the ".abc"-file, it will open up in NOTEPAD:


procedure TForm1.Button1Click(Sender: TObject);
var
  TReg : TRegistry;

begin
  //Create the registry-handler
  TReg := TRegistry.Create;
  //Set the rootkey
  TReg.Rootkey := HKEY_CLASSES_ROOT;
  //First create a subkey that matches the file-extension
  TReg.OpenKey('.abc',True);
  //Then give the key (Standard) a descriptive name
  TReg.WriteString('','Testapplication');

  //Then create a key that matches the ".abc" value (Testapplication)
  TReg.OpenKey('\Testapplication',True);
  //Then create a subkey containing the name of the icon for the extension ".abc"
  TReg.OpenKey('\Testapplication\DefaultIcon',True);
  //Then define what icon to use
  TReg.WriteString('','c:\windows\defrag.exe,7');
  //Then create a subkey that contains the definition for what should happen when
  //a file with that extension is opened
  TReg.OpenKey('\Testapplication\shell',True);
  TReg.OpenKey('open',True); //"open" is created as a subkey to "shell"
  TReg.OpenKey('command',True); //and "command" is created as a subkey to "open"
  //Finally, we associate the "open"-command with the NOTEPAD.EXE program.
  TReg.WriteString('','C:\Windows\NotePad.exe "%1"');
  //Finished!
  TReg.Free;
end;

Good luck!

//Daniel, Sweden
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:fmichaud061597
ID: 1355442
I already have done this and the icon associated with my file type still not show.
0
 

Expert Comment

by:Dippen
ID: 1355443
What version of Delphi are you using? And what OS?
0
 

Expert Comment

by:Dippen
ID: 1355444
One more thing: Does the file association not work after rebooting either? If you like to, you could mail me the code and let me look at it.
0
 

Author Comment

by:fmichaud061597
ID: 1355445
I'm using Delphi 3 with Windows 98.
0
 

Expert Comment

by:Dippen
ID: 1355446
OK, then I'm afraid I have nothing further to add to this discussion... ;-) (I'm using Delphi v2.0 with W95)
   It works for me, but then maybe there is something more that must be put in the W98-registry before it works properly, or some other problem. Good luck!
0
 

Expert Comment

by:zitt
ID: 2391901
Borrowed the code below from another freeware component:

// Update system to notify of association change
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, PChar(''), PChar(''));

Source:
Larry J. Rutledge <lrutledge@jps.net>
http://www.prestwood.com/forums/delphi/sdug/newsletter

To get the code associated with an article, go to the following:
http://www.geocities.com/SiliconValley/Lakes/4339
0
 

Expert Comment

by:zitt
ID: 2391915
Oh... and the unit required for the SH* constants:
uses
   ShlObj;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question