读取INI,下面的例子或许对你有帮助。
ini文件中这样
[database]
Provider=SQLOLEDB.1
Persist Security Info=False
username=sa
databasename=rsgl
servername=jw
procedure Trsgl_login.FormActivate(Sender: TObject);
var i:integer;
ini: TIniFile;
ServerName,S1: string;
UserName, PWD: string;
DatabaseName1:string;
lj:string;
begin
lj:=ExtractFilePath(paramstr(0))+'lmd.ini';
ini := TIniFile.Create(lj);
try
UserName := ini.ReadString('Database', 'UserName', '');
Pwd := ini.ReadString('Database', 'Password', '');
ServerName := ini.ReadString('Database', 'ServerName', '');
DatabaseName1:=ini.ReadString('Database','DatabaseName','');
finally
ini.Free;
end;
rsgl_data.rsgl_connect.Connected := false;
try
S1:='Provider=SQLOLEDB.1;'+
'Password='+PWD+';'+
'Persist Security Info=False;'+
'User ID='+UserName+';'+
'Initial Catalog='+DatabaseName1+';'+
'Data Source='+ServerName+';';
rsgl_data.rsgl_connect.ConnectionString:=S1;
rsgl_data.rsgl_connect.Connected := true;
except
showmessage('连接数据库服务器异常!');
end;
end;
//连接完后
读取数据很简单
放几个控件连接一下就可以实现了。