Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


Get the application associated to an extensionFormat this article printer-friendly!Bookmark function is only available for registered users!
with full path
Product:
Delphi all versions
Category:
System
Skill Level:
Scoring:
Last Update:
05/24/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet associated application getassociation open default
Times Scored:
4
Visits:
3255
Uploader: Eber Irigoyen
Company: BTXSys
Reference: N/A
 
Question/Problem/Abstract:
how do I get the application that opens/executes files with extension ".???"
Answer:



I wrote a function for this purpose:
it returns the application with the full path to where its located, empty if not found

Function GetAssociation(Const Fileext: String): String;
Var
  FileClass, Tmp: String;
  Reg: TRegistry;
Begin
  Result := '';
  Reg := TRegistry.Create(KEY_EXECUTE); //read only please
  Reg.RootKey := HKEY_CLASSES_ROOT;
  FileClass := '';
  If Reg.OpenKeyReadOnly(Fileext) Then
  Begin
    FileClass := Reg.ReadString('');  //read the default
    Reg.CloseKey;
  End;
  If FileClass <> '' Then Begin
    If Reg.OpenKeyReadOnly(FileClass + '\Shell\Open\Command') Then
    Begin
      Result := Reg.ReadString('');
      Reg.CloseKey;
    End;
  End;
  Reg.Free;
  If (Length(Result)>0) Then
    If (Result[1]='"') Then
    Begin
      Delete(Result, 1, 1);
      Result:=Copy(Result, 1, Pos('"', Result)-1)
    End
    Else
    Begin
      Tmp:=ExtractFileExt(Result);
      If (Pos(' ', Tmp)>0) Then
        Tmp:=Copy(Tmp, 1, Pos(' ', Tmp)-1);
      Result:=Copy(Result, 1, Pos(Tmp, Result)+Length(Tmp))
    End
End;

...ok... then as an example: drop a TEdit and a TButton on your form, put the extension that you need on the TEdit, like:
TEdit.Text:='.ZIP'
(don't forget to include the "." before the extension)

then on the onclick event of the button:

Procedure TForm1.Button2Click(Sender: TObject);
Begin
  ShowMessage(GetAssociation(Edit1.Text))
End;

that's it

keep up coding

- The source code of the article was formatted using this unit:
PAS 2 HTML converter

EberSys





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Just curious
    Igor Zenkov (Jun 1 2002 1:09AM)

Why you did not use "FindExecutable" API call?
Respond

RE: Just curious
Eber Irigoyen (Jun 2 2002 6:35AM)

The FindExecutable function retrieves the name and handle to the executable (.EXE) file associated with the specified filename, not with the specified extension
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
C.A. Longen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)