主题:关于.ini文件的操作--求助
procedure Tfrm_dm.DataModuleCreate(Sender: TObject);//窗体模块先创建
var ini,iniW:tinifile;
state:boolean;
Cstring:ansistring;
str,str1:ansistring;
begin
ini:=tinifile.Create(changefileext(application.exename,'.ini'));
state:=ini.readbool('database','connection',false);
if not state then//数据库连接没有成功
try
f_config:=tf_config.create(application);//动态创建服务器配置窗体
f_config.showmodal;
except
on e:exception do
application.showexception(e);
end;
cstring:='provider=sqloledb.1;integrate security=sspi;persist security info=false; initial catalog=';
str:=ini.readstring('database','initial catalog','student_info');//从配置文件中度曲数据库名字符串
cstring:=cstring+str;
str1:=ini.readstring('database','data sourse','microsof-b30447');//读服务器名
cstring:=cstring+';data source=';
cstring:=cstring+str1;
cnn.connected:=false;
cnn.connectionstring:=cstring;
try
cnn.connected:=true;
except
application.messagebox('与数据库服务器连接未成功,请重新配置','警告对话框',mb_ok);
end;
iniW:=tinifile.create(changefileext(application.exename,'.ini'));
state:=cnn.connected;
iniw.writebool('database','connection',state);//将数据库连接是否成功写入配置文件
end;
procedure Tf_config.FormCreate(Sender: TObject);//配置窗口
var filename:string;
inifile:tinifile;
begin
filename:=extractfilepath(application.ExeName)+'student_info.ini';
if not fileexists(filename) then fileclose(filecreate(filename));
end;
procedure Tf_config.RzBitBtn1Click(Sender: TObject);//确定按扭
var inifile:tinifile;
filename:String;
begin
if (trim(rzedit1.Text)='')or (trim(rzedit2.Text)='') then
begin
showmessage('请填写数据库服务器名和数据库名称!');
exit;
rzedit1.SetFocus;
end;
try
filename:=extractfilepath(application.ExeName)+'student_info.ini';
if not fileexists(filename) then fileclose(filecreate(filename));
inifile:=tinifile.Create(filename);
inifile.WriteString('database','initial catalog',rzedit2.Text);
inifile.WriteString('database','data sourse',rzedit1.Text);
//inifile.Free;
except
showmessage('连接服务器失败!');
end;
close;//关闭窗口
end;
按了确定按纽后程序出错"连接字符串属性无效",请问什么原因,大家有什么好的代码吗?
var ini,iniW:tinifile;
state:boolean;
Cstring:ansistring;
str,str1:ansistring;
begin
ini:=tinifile.Create(changefileext(application.exename,'.ini'));
state:=ini.readbool('database','connection',false);
if not state then//数据库连接没有成功
try
f_config:=tf_config.create(application);//动态创建服务器配置窗体
f_config.showmodal;
except
on e:exception do
application.showexception(e);
end;
cstring:='provider=sqloledb.1;integrate security=sspi;persist security info=false; initial catalog=';
str:=ini.readstring('database','initial catalog','student_info');//从配置文件中度曲数据库名字符串
cstring:=cstring+str;
str1:=ini.readstring('database','data sourse','microsof-b30447');//读服务器名
cstring:=cstring+';data source=';
cstring:=cstring+str1;
cnn.connected:=false;
cnn.connectionstring:=cstring;
try
cnn.connected:=true;
except
application.messagebox('与数据库服务器连接未成功,请重新配置','警告对话框',mb_ok);
end;
iniW:=tinifile.create(changefileext(application.exename,'.ini'));
state:=cnn.connected;
iniw.writebool('database','connection',state);//将数据库连接是否成功写入配置文件
end;
procedure Tf_config.FormCreate(Sender: TObject);//配置窗口
var filename:string;
inifile:tinifile;
begin
filename:=extractfilepath(application.ExeName)+'student_info.ini';
if not fileexists(filename) then fileclose(filecreate(filename));
end;
procedure Tf_config.RzBitBtn1Click(Sender: TObject);//确定按扭
var inifile:tinifile;
filename:String;
begin
if (trim(rzedit1.Text)='')or (trim(rzedit2.Text)='') then
begin
showmessage('请填写数据库服务器名和数据库名称!');
exit;
rzedit1.SetFocus;
end;
try
filename:=extractfilepath(application.ExeName)+'student_info.ini';
if not fileexists(filename) then fileclose(filecreate(filename));
inifile:=tinifile.Create(filename);
inifile.WriteString('database','initial catalog',rzedit2.Text);
inifile.WriteString('database','data sourse',rzedit1.Text);
//inifile.Free;
except
showmessage('连接服务器失败!');
end;
close;//关闭窗口
end;
按了确定按纽后程序出错"连接字符串属性无效",请问什么原因,大家有什么好的代码吗?