我对注册类型稍有了解,但具体过程尚不知,能否给我个样例。谢谢。

解决方案 »

  1.   

    在注册表中建立文件关联:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,registry, OleCtrls, ShockwaveFlashObjects_TLB, Menus;type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        flash1: TMenuItem;
        ShockwaveFlash1: TShockwaveFlash;
        procedure flash1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      myreg,reg:TRegistry;
      a:boolean;      //文件关联
    implementation{$R *.dfm}procedure TForm1.Flash1Click(Sender: TObject);
    var
        abc:string;
        abd:string;
    begin
    myreg:=Tregistry.Create;
    if a=false then
    begin
    try
    with myreg dobegin
            abd:=extractfilepath(paramstr(0))+'Player.exe,1';
            abc:=extractfilepath(paramstr(0))+'Player.exe %1';
            myreg.RootKey:=HKEY_CLASSES_ROOT;        if Openkey('\.swf\shell\open\command',true) then
             begin
                 writestring('',abc);
                 myreg.CloseKey;
             end;
             if openkey('\.swf\shell\open',true) then
             begin
                 writestring('','用Player播放');
                 myreg.CloseKey;
            end;        if openkey('\.swf\DefaultIcon',true) then
             begin
                 writestring('',abd);
                 myreg.Free;
                 showmessage('****   关联文件完毕!   ****');
                 flash1.Checked:=true;
                 flash1.Caption:='取消关联';
                 a:=true;
            end;
    end;except
    showmessage('对不起,关联失败了 :(');
    end;endelse
    begin
    try
    with myreg do        begin
            myreg.RootKey:=HKEY_CLASSES_ROOT;
            myreg.DeleteKey('.swf');
            myreg.Free;
            showmessage('****   取消文件关联完毕!   ****');
            flash1.Checked:=false;
            flash1.Caption:='关联flash';
            a:=false;
            end;except
            showmessage('对不起,关联失败了 :(');
    end;end;end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      if Paramstr(1)<>'' then
          begin
            shockwaveflash1.Movie:=Paramstr(1);
            shockwaveflash1.Play;
          end;
    reg:=TRegistry.create;
    reg.RootKey:=HKEY_CLASSES_ROOT;
    with reg do
    begin
      reg.OpenKey('\.swf\shell\open',false);
       if reg.readstring('')='用Player播放' then
         begin
           a:=true;
           flash1.Checked:=true;
           reg.Free;
         end
        else
          begin
            a:=false;
            flash1.Checked:=false;
            reg.Free;
          end;
    end;end;end.