Procedure GetKeys(const FullKey:String;Strings:TStrings);
var
  StrRootKey:string;
  strsubkey:string;
  StrPos:integer;
  Reg:Tregistry;
  RootKey:HKEY;
begin
  StrPos:=pos('\',FullKey);
  StrRootKey:=Copy(FullKey,0,strpos-1);
  StrSubKey:=Copy(Fullkey,strpos+1,Length(fullkey)-strpos);
  RootKey:=StrToHKEY(StrRootKey);
  reg:=Tregistry.Create;
  reg.RootKEY:=RootKEY;
  if reg.OpenKey(StrSubKey,false) then
    if reg.HasSubKeys then
    reg.GetKeyNames(strings); //----------->>>>>这里出错<<<<<----
  reg.CloseKey;
  reg.Free;
end;
===============
unit registryprocedure TRegistry.GetKeyNames(Strings: TStrings);
var
  Len: DWORD;
  I: Integer;
  Info: TRegKeyInfo;
  S: string;
begin
  Strings.Clear;
  if GetKeyInfo(Info) then
  begin
    SetString(S, nil, Info.MaxSubKeyLen + 1);
    for I := 0 to Info.NumSubKeys - 1 do
    begin
      Len := Info.MaxSubKeyLen + 1;
      RegEnumKeyEx(CurrentKey, I, PChar(S), Len, nil, nil, nil, nil);
      Strings.Add(PChar(S));
    end;
  end;
end;

解决方案 »

  1.   

    把报错贴上来,还有你原来的程序的变量不可能就是strings吧?
      

  2.   

    TO Geranium:
    就是Strings,这有关系吗?
    编译没错误,只是执行该过程就出错
      

  3.   

    你传递STRINGS的时候CRATE了吗?
      

  4.   

    晕~~~~忘了Create 了。
      

  5.   

    procedure TFrm_main.Button3Click(Sender: TObject);
    var Strs:TStrings;
        i:Integer;
    begin
      Strs:=TStrings.Create;
      GetKeys('HKEY_CURRENT_USER\Software\Microsoft',Strs);
      if strs.Count > 0 then
      for i:=0 to strs.Count-1 do
      begin
        memo1.Lines.Add(strs.Strings[i]);
      end;  Strs.Free;
    end;
    错误提示:
    [Warning] Unit1.pas(220): Constructing instance of 'TStrings' containing abstract method 'TStrings.Clear'
    [Warning] Unit1.pas(220): Constructing instance of 'TStrings' containing abstract method 'TStrings.Delete'
    [Warning] Unit1.pas(220): Constructing instance of 'TStrings' containing abstract method 'TStrings.Insert'
    -------------abstract Error
      

  6.   

    Strs:TStrings
    不能用Create 方法。因为他的Create是一个抽象的方法。
    要创建的时候,Strs:=TStringList.Create来创建。