
24.10.2008, 15:14
|
Модератор
|
|
Регистрация: 17.04.2008
Сообщения: 8,087
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
|
|
С помощью объекта TRegistry.
Примерно так:
Код:
uses
Registry;
// procs
procedure SaveListToReg(AList : TStringList; AKey : String);
var
R : TRegistry;
I, C : Integer;
begin
R := TRegistry.Create;
R.RootKey := HKEY_CURRENT_USER;
Try
If R.OpenKey(AKey,True) Then
Begin
C := AList.Count;
R.WriteInteger('Count',C);
For I := 0 To C-1 Do
R.WriteString('Item ' + IntToStr(I),AList[i]);
R.CloseKey;
End;
Finally
R.Free;
End;
end;
procedure LoadListFromReg(AList : TStringList; AKey : String);
var
R : TRegistry;
I, C : Integer;
begin
AList.Clear;
R := TRegistry.Create;
R.RootKey := HKEY_CURRENT_USER;
Try
If R.OpenKeyReadOnky(AKey) Then
Begin
If R.ValueExists('Count') Then
Begin
C := R.ReadInteger('Count');
For I := 0 To C-1 Do
If R.ValueExists('Item ' + IntToStr(I)) Then
AList.Add(R.ReadString('Item ' + IntToStr(I));
End;
R.CloseKey;
End;
Finally
R.Free;
End;
end;
// usage
procedure Form1Create(...);
begin
LoadListFromReg(ComboBox1.Items,'Software\MySoft\Combo1');
end;
procedure From1Close(...);
begin
SaveListToReg(ComboBox1.Items,'Software\MySoft\Combo1');
end;
|