为什么不用cnpack专家包,它做了一个自动生成操作ini文件单元的功能,
假设有abc.ini,格式如下
[xxx]
a=123
b=456
c=789
则操作该文件的单元
unit Unit1;
interface
uses
Classes, SysUtils, IniFiles, Forms, Windows;
const
csInixxxSection = 'xxx';
{Section: xxx}
csInixxxa = 'a';
csInixxxb = 'b';
csInixxxc = 'c';
type
TIniOptions = class(TObject)
private
Fxxxa: Integer;
Fxxxb: Integer;
Fxxxc: Integer;
public
procedure LoadSettings(Ini: TIniFile);
procedure SaveSettings(Ini: TIniFile);
property xxxa: Integer read Fxxxa write Fxxxa;
property xxxb: Integer read Fxxxb write Fxxxb;
property xxxc: Integer read Fxxxc write Fxxxc;
end;
var
IniOptions: TIniOptions = nil;
implementation
procedure TIniOptions.LoadSettings(Ini: TIniFile);
begin
if Ini <> nil then
begin
Fxxxa := Ini.ReadInteger(csInixxxSection, csInixxxa, 123);
Fxxxb := Ini.ReadInteger(csInixxxSection, csInixxxb, 456);
Fxxxc := Ini.ReadInteger(csInixxxSection, csInixxxc, 789);
end;
end;
procedure TIniOptions.SaveSettings(Ini: TIniFile);
begin
if Ini <> nil then
begin
Ini.WriteInteger(csInixxxSection, csInixxxa, Fxxxa);
Ini.WriteInteger(csInixxxSection, csInixxxb, Fxxxb);
Ini.WriteInteger(csInixxxSection, csInixxxc, Fxxxc);
end;
end;
initialization
IniOptions := TIniOptions.Create;
finalization
IniOptions.Free;
end.