• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Register a file type for my program...

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
zicodt
Asked:
zicodt
  • 3
  • 3
  • 2
  • +1
1 Solution
 
mirghaniCommented:
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
 
mirghaniCommented:
Sorry, I forget to logout from mirghani account
0
 
MotazCommented:
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
Industry Leaders: 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!

 
zicodtAuthor Commented:
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
 
Stuart_JohnsonCommented:
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
 
zicodtAuthor Commented:
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
 
Stuart_JohnsonCommented:
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
 
zicodtAuthor Commented:
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
 
Stuart_JohnsonCommented:
The points were OK for what you were asking - it wasn't an overly complicated question.
0
 
MotazCommented:
Thanks Johnson for helping zicodt, and thanks zicodt for the points
Motaz
0

Featured Post

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!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now