使用注册表比较安全:
在窗体创建时调用reg_read过程,在窗体关闭时调用reg_write过程。
//从注册表读值
procedure reg_read(var s1:string);
var reg:Tregistry;
begin
reg:=Tregistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('/Software/project1', True) ;
S1:=Reg.ReadString('VALUE1');
finally
Reg.closekey;
Reg.free;
end;
end;
//值读入注册表
procedure Reg_write(var s1:string);
var reg:Tregistry;
begin
reg:=Tregistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('/Software/project1', false) then
Reg.WriteString('value1',s1);
finally
Reg.closekey;
Reg.free;
end;
end;
注意在USES中加入registry。