Home > Software design >  How to get the Delphi Projects MRU List?
How to get the Delphi Projects MRU List?

Time:01-02

I am trying to get the Projects MRU List from specific Delphi versions:

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;

Usage:

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;

I am stuck at getting the list of closed projects.

CodePudding user response:

At least on my system, the registry values are named File_0, File_1, and so on, so retrieving this list is easy:

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;

(Please note that it doesn't make sense to let the MRUList be a var parameter.)

Usage:

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;
  • Related