0

我正在尝试从特定的 Delphi 版本中获取项目 MRU 列表:

function GetDelphiMRUList(const verstr: string; var MRUList: TStringList): Boolean;
var
  Reg: TRegistry;
begin
  Result := False;
  MRUList.Text := '';
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    Reg.OpenKeyReadOnly('SOFTWARE\Embarcadero\BDS\' + verstr);
    Result := Reg.KeyExists('Closed Projects');
    Reg.CloseKey;
    if Result then
    begin
      // How to get the MRUList?

    end;
  finally
    Reg.Free;
  end;
end;

用法:

procedure TForm1.FormCreate(Sender: TObject);
begin
  var MRUList: TStringList;
  MRUList := TStringList.Create;
  try
    if GetDelphiMRUList('22.0', MRUList) then
      CodeSite.Send('TForm1.FormCreate: MRUList', MRUList);
  finally
    MRUList.Free;
  end;
end;

我一直在获取已关闭项目的列表。

4

1 回答 1

2

至少在我的系统上,注册表值被命名为File_0,File_1等等,所以检索这个列表很容易:

function GetDelphiMRUList(const verstr: string; MRUList: TStringList): Boolean;
begin
  var Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    Result := Reg.OpenKey('SOFTWARE\Embarcadero\BDS\' + verstr + '\Closed Projects', False);
    if Result then
    begin
      MRUList.Clear;
      var i := 0;
      while Reg.ValueExists('File_' + i.ToString) do
      begin
        MRUList.Add(Reg.ReadString('File_' + i.ToString));
        Inc(i);
      end;
    end;
  finally
    Reg.Free;
  end;
end;

MRUList(请注意,让成为参数是没有意义的var。)

用法:

procedure TForm1.FormCreate(Sender: TObject);
begin
  var List := TStringList.Create;
  try
    if GetDelphiMRUList('21.0', List) then
      Memo1.Lines.Assign(List)
    else
      Memo1.Text := 'Couldn''t get MRU list.';
  finally
    List.Free;
  end;
end;
于 2022-01-01T19:13:00.690 回答