procedure TDMData.DataModuleCreate(Sender: TObject);
Var
fileSet:TextFile;
begin
//检查是否存在
if FileSearch('run.ini','/') <> 'run.ini' then
begin
AssignFile(FileSet,'run.ini');
Rewrite(FileSet);
Writeln(fileSet,';连接数据库服务器字符串');
Writeln(fileSet,'[CONN]
rovider=SQLOLEDB.1;Password=zd;Persist Security Info=True;' +
'User ID=sa;Initial Catalog=E_Warehouse;Data Source=192.168.0.4;Use ' +
'Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use ' +
'Encryption for Data=False;Tag with column collation when possible=False');
CloseFile(FileSet);
end;
Try
Connection.Connected := False;
Connection.ConnectionString := GetConnString;
Connection.Connected := True;
except
showmessage('数据库服务器连接不上,请确认是否连接数据库');
application.Terminate;
end;
end;
Function TDMData.GetConnString():string;
Var
FileSet:TextFile;
fLength,i:Integer;
fLine:String;
list:Boolean;
begin
AssignFile(FileSet,'run.ini');
//打开配置文件
Reset(FileSet);
//定位文件头
// fLength := FileSize(FileSet);
// list := EOF(fileSet);
// For i := 1 To fLengthdo
While NOT EOF(fileSet)do
begin
Readln(FileSet,fLine);
//读取一行数据
if MidStr(fLine,1,7) = '[CONN]:' then
//检查是否是连接字符串
begin
Result := MidStr(fLine,8,Length(fLine)-7);
//获取连接字符串
CloseFile(FileSet);
//关闭文件
Exit;
//退出
end;
end;
Result := '';
CloseFile(FileSet);
//关闭文件
end;
end.
//安行读取!!