?
Solved

Register a file type for my program...

Posted on 2003-03-16
10
Medium Priority
?
269 Views
Last Modified: 2010-04-04
Hi all,

I would like to create a button on my program to register a file type for it...

The file extension is .nfo, and I would like to when I click the icon in windows my program opens...

Thanks for the help...
0
Comment
Question by:zicodt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 

Expert Comment

by:mirghani
ID: 8146761
Put this code in your project's OnCreate event,
the application you want to be opened when
double clicking on .nfo file:

// Add Registry to uses clause, the post this code:

var
  Regs: TRegistry;
begin
  Regs:= TRegistry.Create;
  Regs.RootKey:= HKEY_CLASSES_ROOT;

  (*** Check if extension already registred ***)
  if Regs.OpenKey('.nfo', False) then
  begin
    Regs.CloseKey;
    Regs.Free;
    Exit; (*>>>>>>>>>>>>>>>>*)
  end;

  Regs.OpenKey('\.nfo', True);
  Regs.WriteString('', 'YourProject.Data');
  Regs.OpenKey('\YourProject.Data\Shell\Open\Command', True);
  Regs.WriteString('', ParamStr(0) + ' %1');

  (*** Select an Icon for .esn files ***)
  Regs.OpenKey('\YourProject.Data\DefaultIcon', True);
  Regs.WriteString('', ParamStr(0) + ',0'); // First Icon in exe
  Regs.CloseKey;
  Regs.Free;

end;


Motaz
0
 

Expert Comment

by:mirghani
ID: 8146767
Sorry, I forget to logout from mirghani account
0
 
LVL 7

Accepted Solution

by:
Motaz earned 80 total points
ID: 8146780
Sorry zicodt, and sorry mirghani, I re-login using my account now, and here is the answer again:

Put this code in your project's OnCreate event, in
the application you want to be opened when some one
double click on .nfo file:

// Add Registry to uses clause, the post this code:

var
 Regs: TRegistry;
begin
 Regs:= TRegistry.Create;
 Regs.RootKey:= HKEY_CLASSES_ROOT;

 (*** Check if extension already registred ***)
 if Regs.OpenKey('.nfo', False) then
 begin
   Regs.CloseKey;
   Regs.Free;
   Exit; (*>>>>>>>>>>>>>>>>*)
 end;

 Regs.OpenKey('\.nfo', True);
 Regs.WriteString('', 'YourProject.Data');
 Regs.OpenKey('\YourProject.Data\Shell\Open\Command', True);
 Regs.WriteString('', ParamStr(0) + ' %1');

 (*** Select an Icon for .esn files ***)
 Regs.OpenKey('\YourProject.Data\DefaultIcon', True);
 Regs.WriteString('', ParamStr(0) + ',0'); // First Icon in exe
 Regs.CloseKey;
 Regs.Free;

end;


Motaz
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:zicodt
ID: 8147430
Okay thanks for replying motaz...

I got an error tough, I took a screenshot of the code for you to see... copy this address on the clipboard and paste on your browser to see the error: http://www.tempdir.hpg.com.br/temp/error.jpg

In the code you provided, the "YourProjectData", I need to change it to my project folder name?

Thanks again...
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 8147796
Generally, the idea is an expert provides you with a portion of source code to help you get going - not write the whole program for you.  

What Motaz provided you was a portion of a procedure which you would copy into your application.  Where you place it is upto you, but under normal situations, it would be placed in the FormCreate procedure.

procedure TForm1.FormCreate(Sender: TObject);
var
  Regs: TRegistry;
begin
  Regs:= TRegistry.Create;
  Regs.RootKey:= HKEY_CLASSES_ROOT;
  (* extra code here*)
  Regs.Free;
end;

Just remember, part of learning is trial and error.  Have a look at what people post and see if you can figure out the error instead of asking straight away.  Especially for low-point questions.  People are happy to help, but you must also attempt to help yourself.

Good luck!

Stuart.


Extra note:
The use of try..finally blocks should be used to ensure the registry object is freed.
0
 
LVL 1

Author Comment

by:zicodt
ID: 8149118
Yeah... I'm just starting on delphi... trying to learn on myself... but thanks for all the help...

I'm new to this forum... I know that I can "Accept comment as answer" and give you a reward, but since both of you helped me how can I reward both of you?
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 8149144
Motaz provided you with a working solutions - he deserves the points.  I just added a little bit extra info to it.  So, it's cool.  Save your points for your next question.
0
 
LVL 1

Author Comment

by:zicodt
ID: 8149292
Okay, thanks for explaining me about the forum, I wasn't quite sure about this points thingy, that's why I gave a low-point question... now I'm aware of it.. thanks again...
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 8149308
The points were OK for what you were asking - it wasn't an overly complicated question.
0
 
LVL 7

Expert Comment

by:Motaz
ID: 8150022
Thanks Johnson for helping zicodt, and thanks zicodt for the points
Motaz
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

801 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