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

Register New File Extension

Hi all,

I need to register an extension.
I basically want to create a new file extension called 'VRA'  and when a file called VRA is doubleclicked my program then runs.
I also need to add a parameter (The Filename executed) to my program.

Hope you can help!

Thanks

ST3VO
0
ST3VO
Asked:
ST3VO
  • 7
  • 7
1 Solution
 
MerijnBSr. Software EngineerCommented:
usage: RegisterMyFileExtension('VRA', YourApplicationFullPath, 'ST3VO super app');

function RegisterMyFileExtension(myext: string; myapp:string; desc:string): boolean;
var Reg: TRegistry;
begin
      Reg:= TRegistry.Create;

      Reg.RootKey := HKEY_CLASSES_ROOT;

      //add extension
      Reg.OpenKey('.' + myext, true);
      Reg.WriteString('', myext + '_auto_file');
      Reg.CloseKey;

      //add information of extension
      Reg.OpenKey(myext + '_auto_file', True);
      Reg.WriteString('', desc);
      Reg.CloseKey;

      //add default application
      Reg.OpenKey(myext + '_auto_file\shell\open\command', true);
      Reg.WriteString('', '"'+ myapp + '" "%1"');
      Reg.CloseKey;


      //add icon
      Reg.OpenKey(myext + '_auto_file\DefaultIcon', true);
      Reg.WriteString('', '"'+ myapp + '",0');
      Reg.CloseKey;

      Reg.Free;
end;
0
 
ST3VOAuthor Commented:
Do I have to refresh the registry so it will link the file extension to my application?

I've run the code and build a test.vra file but when I double-click on it it still doesn't execute my application.

It brings up the Search for Application list form. I can see that My Application is now on the list so how to I make it so I don't have to select it from the list manually?

Thanks again

ST3VO
0
 
MerijnBSr. Software EngineerCommented:
you can do this to 'force' an update:

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
0
Independent Software Vendors: 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!

 
ST3VOAuthor Commented:
Great that did the job great! I just need to know the last part of my question:

<<I also need to add a parameter (The Filename executed) to my program.>> ???
0
 
MerijnBSr. Software EngineerCommented:
if you want your application to 'register itself' you can use Application.Exename
0
 
ST3VOAuthor Commented:
It's working perfect now but I just need to pass a parameter into my loading application into any variable or component when my application is execute via a registered file .....VRA

0
 
MerijnBSr. Software EngineerCommented:
sorry, I don't understand what you mean
0
 
ST3VOAuthor Commented:
When I click on the new file extension my application loads...When my application is loaded I need to pass a parameter to my application for example the filename of the file that was clicked for loading my application.

For example:

1. I double-click a file called "test.vra"
2. My Application loads
3. Onloaded I pass a string called "test.vra" to a memo for example.

Hope this explains it better.
0
 
MerijnBSr. Software EngineerCommented:
afaik, the filename double clicked will automatically set as parameter to your application
0
 
ST3VOAuthor Commented:
afaik ???
0
 
MerijnBSr. Software EngineerCommented:
afaik = as far as I know :)
0
 
ST3VOAuthor Commented:
And how do I access that information?
0
 
MerijnBSr. Software EngineerCommented:
user ParamStr(1).

var FileToLoad: string;
begin
 FileToLoad := ParamStr(1);
0
 
ST3VOAuthor Commented:
Perfect! Thanks a million for your help!!! :o)

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now