我正在尝试从特定的 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;
我一直在获取已关闭项目的串列。
uj5u.com热心网友回复:
至少在我的系统上,注册表值被命名为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;
0 评论