存储
var
color:tcolor;
SysIni:Tinifile;
FileName:string;
begin
color:=clred;
FileName:='C:\abc.ini';
SysIni:=Tinifile.Create(FileName);
try
SysIni.WriteString('color','color1',Inttostr(color));
except
end;
SysIni.Free;
end
读取
var
color:tcolor;
SysIni:TIniFile;
FileName:string;
begin
FileName := 'C:\abc.ini';
SysIni:=TIniFile.Create(FileName);
try
color:=strtoInt(SysIni.ReadString('Color','Color1','0'));
except
end;
SysIni.Free;
end;
●读取数据的方法
function ReadBinaryData(const Name: String; var Buffer; BufSize: Integer):Integer;
function ReadBool(const Name: String): Boolean;
function ReadCurrency(const Name: String): Currency;
function ReadDate(const Name: String): TDateTime;
function ReadDateTime(const Name: String): TDateTime;
function ReadFloat(const Name: String): Double;
function ReadInteger(const Name: String): Integer;
function ReadString(const Name: String): String;
function ReadTime(const Name: String): TDateTime;
以上方法从当前主键读取相应数据类型的键值的数据,如果类型不匹配将产生一个异常。
●RegistryConnect方法
function RegistryConnect(const UNCName: String): Boolean;
与另一台计算机的注册表建立连接,在建立连接前应将Rootkey属性设为HKEY_USERS或HKEY_LOCAL_MACHINE。
UNCName是另一台计算机的名子。格式如:\computername
假如UNCName为nil,将打开本地计算机。
var
Ini :TIniFile;
Ini_Path :String;
begin
Ini_Path := ExtractFilePath(paramstr(0))+'Color_config.ini';
Ini := TIniFile.Create(Ini_Path);
Ini.WriteInteger('Color','value',ColorToRGB(clRed));
...
end;