TRegister...
帮助有详细解释

解决方案 »

  1.   

    unit Main;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ComCtrls, ExtCtrls,Registry;type
      TForm1 = class(TForm)
        GroupBox1: TGroupBox;
        Label1: TLabel;
        Edit1: TEdit;
        Label2: TLabel;
        Edit2: TEdit;
        GroupBox2: TGroupBox;
        Label3: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        Edit3: TEdit;
        Edit4: TEdit;
        Edit5: TEdit;
        GroupBox3: TGroupBox;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        NameofKey: TEdit;
        Label6: TLabel;
        Label7: TLabel;
        Label8: TLabel;
        Label9: TLabel;
        ValueforKey: TEdit;
        procedure RegistryKeys(Path:String);
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      DKey:AnsiString;
      implementation{$R *.DFM}procedure TForm1.RegistryKeys(Path:string);
    Var
      Reg: TRegistry;
      I,J:Integer;
      NewKey:String;
      TreeNode,SubTreeNode:TTreeNode;
    begin
     Reg:=TRegistry.Create;
      try
       Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry
        if not Reg.OpenKey(DKey+Path,False) then
         Showmessage('Error did not find any Main keys under '+Dkey)
        else
        If Path = 'Database Engine' then
        begin
         Edit1.Text:= Reg.ReadString('ConfigFile01');
         Edit2.Text:= Reg.ReadString('DLLPath');
        end
        else
         begin
          Edit3.Text:= Reg.ReadString('Delphi 2.0');
          Edit4.Text:= Reg.ReadString('RootDir');
          Edit5.Text:= Reg.ReadString('Version');
         end;
      finally
         Reg.Free;
    end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     DKey := '\Software\Borland\';          // Sets the root for the registry.
     RegistryKeys('Database Engine');      // Get the delphi registry keys
     RegistryKeys('Delphi\2.0');           // Get the delphi registry keys
    end;procedure TForm1.Button1Click(Sender: TObject);
    Var
      Reg: TRegistry;
    begin
    If length(NameofKey.Text) or Length(ValueforKey.Text) <=0 then
     Showmessage('You must fill both fields for the demo')
    else
     begin
      Reg:=TRegistry.Create;
      try
       Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry
        if not Reg.OpenKey('Software\Delphi Demo\'+NameofKey.Text,False) then
         If MessageDlg('This specified key does not exist do you wish to created it'
                     ,Mtinformation,[mbYes,mbNo],0)=mryes then
          begin
           Reg.CreateKey('Software\Delphi Demo\'+NameofKey.Text);
            If not Reg.OpenKey('Software\Delphi Demo\'+NameofKey.Text,False) then
              ShowMessage('Error in Opening Created Key')
            else
            Reg.WriteString('Value1',ValueForKey.Text);
          end
         else
          ShowMessage('Key was not created');
      finally
       Reg.Free;
      end;
     end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    Var
      Reg: TRegistry;
    begin
      Reg:=TRegistry.Create;
      try
       Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry
       If Not Reg.DeleteKey('Software\Delphi Demo') then
        ShowMessage('Unable to delete the key')
       else
        ShowMessage('Key deleted OK')
      finally
       Reg.Free;
      end;
    end;procedure TForm1.Button3Click(Sender: TObject);
    Var
      Reg: TRegistry;
      Val:TStringList;
      I:Integer;
    begin
      Reg:=TRegistry.Create;
      Val:=TStringList.Create;
      try
       Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry
        if not Reg.OpenKey('Software\Delphi Demo\'+NameofKey.Text,False) then
         ShowMessage('Error in opening key')
        else
         begin
          Reg.GetValueNames(Val);
          For I:=0 to Val.Count-1 do
           begin
            ShowMessage('Key Software\Delphi Demo\'+Chr(13)+
                        'Has a Key named             '+NameofKey.Text+Chr(13)+
                        'With an Entry Called        '+Val.Strings[I]+Chr(13)+
                        'With a Value of             '+Reg.ReadString(Val.Strings[I]));
           end;
         end;  finally
       Reg.Free;
       Val.Free;
      end;end;end.
      

  2.   


      看来afeisky(刀光剑影)老兄的代码挺不错的  试试看吧
      

  3.   

    在Delphi中查TRegistry的帮助,那个比较详细。
      

  4.   

    faint,Delphi也是E文的啊,你可以慢慢调试看看,把程序放到你的工程中调试一下就知道了.
    你新建一个Form1工程,按我的程序放上几个Label1和Edit.....控件,运行一下就知道了.