unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,iniFiles{一定添加此单元};
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{配置文件操作函数:传入文件名字}
procedure OperateIniFiles(fileName:String);
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.OperateIniFiles(fileName: String);
var
ini :TiniFile;
vuserName,vPwd:string;
vid:integer;
begin
if not FileExists(FileName) then exit;//首先判断文件是否存在,若不存在则退出。
ini := TiniFile.Create(fileName);
try
{分别读取配置文件中的 区,字段,默认值一般为空,若数字可设为0或-1}
vuserName := ini.ReadString('Database','userName','');
vPwd := ini.ReadString('Database','Password','');
vid := ini.ReadInteger('Database','id','-1');
finally
{最后释放配置文件}
ini.Free;
end;
end;