Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - Creating an Associator
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Creating an Associator
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-08-09

    Table of Contents:
  • Creating an Associator
  • Continuing with the code
  • How to enable the application to load the file that has been clicked
  • The entire code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating an Associator - The entire code


    (Page 4 of 4 )

    unit appassoc;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, Buttons,registry;
    type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Panel2: TPanel;
        Panel3: TPanel;
        StaticText1: TStaticText;
        StaticText2: TStaticText;
        edappname: TEdit;
        edExt: TEdit;
        StaticText3: TStaticText;
        btnAssoc: TBitBtn;
        btnClose: TBitBtn;
        StaticText4: TStaticText;
        btnbrowse: TSpeedButton;
        StaticText5: TStaticText;
        op: TOpenDialog;
        StaticText7: TStaticText;
        procedure btnCloseClick(Sender: TObject);
        procedure btnbrowseClick(Sender: TObject);
        procedure btnAssocClick(Sender: TObject);

      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.dfm}
    procedure TForm1.btnCloseClick(Sender: TObject);
    begin
    close;
    end;
    procedure TForm1.btnbrowseClick(Sender: TObject);
    begin
    if op.Execute then begin
    edappname.Text:=op.FileName;
    end
    end;
    procedure TForm1.btnAssocClick(Sender: TObject);
    var
    reg:tregistry;
    error:boolean;
    begin
    if (edappname.text = '') OR (edext.text = '') then begin
    MessageDlg('Please ensure that you''ve filled in ALL the fields.', mtError,      [mbOk], 0);
    exit;
    end;
    reg := TRegistry.Create;
    reg.RootKey := HKEY_CLASSES_ROOT;
    reg.LazyWrite := false;
    try
    if
    {Add Program Support}
     reg.OpenKey('.'+edExt.Text+'shellopencommand', true) then begin
    {Invoke the program passing the file name as the first parameter}
    reg.WriteString('', edappname.Text+' %1 ');
    {Add Icon Display}
    reg.CloseKey;
    error:=false;
    end
    else begin
    error:=true;
    end;
    if not error then begin
    reg.OpenKey('.'+edExt.Text+'DefaultIcon', true);
     {Use the first icon in the executable to display}
     reg.WriteString('', edappname.Text+',0');
     reg.CloseKey;
     end;
     if error then begin
     MessageDlg('There''s been an error creating this association, please check that you''ve entered the information correctly.', mtInformation   ,

          [mbOk], 0);
    exit;
          end
          else begin
     if MessageDlg(extractfilename(edappname.Text)+ ' have now been associated ' +#13#10+ 'with ' +'extention - '+ '.'+edExt.Text+'!'#13#10+'Would you like to make another Association?', mtInformation          , [mbYes, mbNo], 0) = mrYes then
      begin
        edext.Clear;
        edappname.Clear;
       end
       else begin
       close;
       end;
       end;
          //************
    finally
    reg.Free;
    end;
    close;
    end;
    end.

    Conclusion

    That's it! You can now associate as many extensions with your application as you like. Because this application involves changing the system registry, I would strongly advice you to back up your registry, in the unlikely case that something goes wrong.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    DELPHI-KYLIX ARTICLES

    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT