我用INI配置文件进行登录数据库,在数据模块中进行INI的验证,当登录不了系统,执行application.Terminate ,然后又有一次连接,因为我的登录窗体中也要先用到数据模块中的连接,这样会进行两次的验证,第二次时就不再执行application.Terminate 了,程序一直运行~~为什么呢???
解决方案 »
- 求游戏自动走路(绕开障碍)算法
- 想学学利用delphi存储网页flash和shockwave视频流技术
- 请问一个正则
- 关于property
- 哪位哥哥姐姐遇到这样的问题?帮帮我呀
- 新手问 关于MIS的 数据库连接??
- 我想使dbgrid中某个字段的值不能被修改?怎么办?
- 在消息钩子中,我可以拦截任意进程的WM_CLOSE,但是怎么阻止该消息继续往下传递呢?
- 如何让程序在windows启动时,自动运行
- 有谁能给我发一个ADO26的升级补丁,是可以解决空记录问题的,我的邮箱是[email protected]
- 【各位老大,C++定义如何转化成PASCAL定义。200分】
- 急!!明天要交任务了,定时自动生成HTML!
program Project1;uses
Forms,
Windows,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm2, Form2); //登陆窗体
if 登陆成功 then
begin
Application.CreateForm(TForm1, Form1); //主窗体
Application.Run;
end else
begin
MessageBox(Application.Handle, '登陆错误', PChar(Application.Title), MB_OK or MB_ICONERROR);
end;
end.
procedure TDataModule1.DataModuleCreate(Sender: TObject);
var
addsini:Tinifile;
s1,user,database,server,password:string;
if_windows_login:boolean;
begin
addsini:=Tinifile.Create(extractfilepath('d:\润丰房产\data\')+'login.ini');
try
user:=addsini.ReadString('Database','User','');
database:=addsini.ReadString('Database','database','');
server:=addsini.ReadString('Database','server','');
password:=addsini.ReadString('Database','password','');
if_windows_login:=addsini.ReadBool('database','if_windows_login',false);
finally
addsini.Free;
end;
ADOConnection1.Connected:=false;
try
begin
if if_windows_login then
s1:='Provider=SQLOLEDB.1;'+
'Integrated Security=SSPI;Persist Security Info=False;'+
'Initial Catalog='+database+';Data Source='+server+''
else
S1:='Provider=SQLOLEDB.1;'+
'Password='+password+';'+
'Persist Security Info=False;'+
'User ID='+user+';'+
'Initial Catalog='+database+';'+
'Data Source='+Server+';'+
'Use Procedure for Prepare=1;'+
'Auto Translate=True;'+
'Packet Size=4096;'+
'Workstation ID=hx05;'+
'Use Encryption for Data=False;'+
'Tag with column collation when possible=False';
end;
ADOConnection1.ConnectionString:=s1;
ADOConnection1.Connected:=true;
except
application.MessageBox('数据库连接失败,请检查配置文件','连接错误',mb_iconstop+MB_OK);
application.Terminate; end;
end;end.
还有一个就是登录窗体上有这句话: ado_tmp.Connection:=datamodule1.ADOConnection1;
程序主窗体上有这句话:procedure TE_MainF.FormCreate(Sender: TObject); //ONCREATE事件触发登录界面窗体
begin
datamodule1:=tdatamodule1.Create(self);
if not assigned(E_loginF) then
E_loginF:=TE_loginF.create(self);
E_loginF.ShowModal;
也就是会进行两次连接,不懂为什么第二次的时候怎么就不执行application.terminate了
ADOConnection1.ConnectionString:=s1;
ADOConnection1.Connected:=true;
建议改为:
ADOConnection1.ConnectionString:=s1;
ADOConnection1.Open;
if not ADOConnection1.Connected then
begin
application.MessageBox('数据库连接失败,请检查配置文件','连接错误',mb_iconstop+MB_OK);
application.Terminate;
end;
Forms,
Windows,
Controls,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {frmLogin},
Unit3 in 'Unit3.pas' {DataModule3: TDataModule};{$R *.res}var
frm: TfrmLogin;begin
Application.Initialize;
Application.CreateForm(TDataModule3, DataModule3); //数据库连接
frm := TfrmLogin.Create(nil);
if frm.ShowModal = mrOk then
begin
frm.Free;
Application.CreateForm(TForm1, Form1);
Application.Run;
end else
begin
frm.Free;
MessageBox(Application.Handle, '登陆错误', 'Error', MB_OK or MB_ICONERROR);
end;
end.
-------------------------------------
登陆窗体的单元
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TfrmLogin = class(TForm)
btnLogin: TButton;
procedure btnLoginClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;implementation{$R *.dfm}procedure TfrmLogin.btnLoginClick(Sender: TObject);
begin
if {登陆成功}True then //在这儿判断登陆是否成功
Self.ModalResult := mrOk
else
Self.ModalResult := mrAbort;
end;end.