//RWini.pas
{
模块名称:配置文件读写
编写人:blue
编写日期:2003-4-26
模块功能:从系统配置文件中读取系统运行所需的各项参数
将系统运行所需的各项参数写入系统配置文件
生成数据库连接字符串
}
unit RWini;
interface
uses INIFiles;
const strINIname = 'db.ini';//INI文件的文件名,大家根据具体情况修改
var
iniParam : TINIFile;
strLocal : String;
procedure readParam(out server:String;out
database:string;out user:string;out password:string);
procedure writeParam(server:string;database:string;
user:string;password:string);
function getConnStr:string;
implementation
procedure readParam(out server:String;out database:string;
out user:string;out password:string);
begin
//从配置文件中读取数据库连接参数
server := iniParam.ReadString('dbParam','Data Source','');
database := iniParam.ReadString('dbParam','Initial Catalog','');
user := iniParam.ReadString('dbParam','User ID','');
password := iniParam.ReadString('dbParam','Password','');
end;
procedure writeParam(server:string;database:string;
user:string;password:string);
begin
//将数据库连接参数写入配置文件
iniParam.WriteString('dbParam','Data Source',server);
iniParam.WriteString('dbParam','Initial Catalog',database);
iniParam.WriteString('dbParam','User ID',user);
iniParam.WriteString('dbParam','Password',password);
end;
function getConnStr:String;
var
server,database,user,password : String;
begin
//生成数据库连接串
readParam(server,database,user,password);
result := 'Provider=SQLOLEDB.1;Password=' + password + ';
Persist Security Info=True;User ID=' + user + ';
Initial Catalog=' + database + ';Data Source=' + server;
end;
initialization
getDir(0,strLocal);
iniParam := TINIFile.Create(strLocal + '\' + strINIname);
finalization
iniParam.Free;
end. |