程序在启动时,闪现两个窗口之后就自动关闭了,本来是对这两个窗口(LoginForm,ConfgForm)进行操作,可是窗口一创建Show出来后马上就自动关闭,随之主窗口关闭,这两个窗口的visiable已经设为false,不知道是什么原因,第一次遇见这种情况。下面是相关的代码,麻烦各位看看:
Project文件代码:
program Client;uses
Forms,
frmClient in 'frmClient.pas' {ClientForm},
u_public in 'u_public.pas',
uSerCfg in 'uSerCfg.pas' {ConfgForm},
uLogin in 'uLogin.pas' {LoginForm};{$R *.res}begin
Application.Initialize;
Application.Title := '轨道交通资料管理客户端';
Application.CreateForm(TConfgForm, ConfgForm);
Application.CreateForm(TLoginForm, LoginForm);
Application.CreateForm(TClientForm, ClientForm);
Application.Run;
end.主窗口创建时的代码:
procedure TClientForm.FormCreate(Sender: TObject);
begin
if not ConnectAppServ then
Application.Terminate; //如果未连接应用服务器,就退出应用程序。
ConfgForm.close;
if not LoginExecute(TLoginForm) then //如果身份验证无效,就退出系统
Application.Terminate;
end;ConnectAppServ:
function ConnectAppServ: boolean; //判断是否连接上了应用服务器
var
vs_Host, vs_Address, vs_Port: string;
reg: TRegistry;
begin
Result := True;
reg := Tregistry.create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
ClientForm.SocketConnection1.Connected := false;
//读取注册表配置的应用服务器信息
if Reg.OpenKey('\Software\物资管理', False) then
begin
vs_Host := reg.ReadString('Host');
vs_Address := reg.ReadString('Address');
vs_Port := reg.readstring('Port');
try
//测试连接
with ClientForm do
begin
SocketConnection1.Address := vs_Address;
SocketConnection1.Host := vs_Host;
SocketConnection1.Port := strtoint(vs_Port);
SocketConnection1.Connected := true;
end;
reg.closekey;
except //未连接上,弹出配置窗口
reg.closekey;
if not ConfgExecute(TConfgForm) then
Result := False;
end;
end
else
begin
if not ConfgExecute(TConfgForm) then //如果没有注册信息,弹出配置窗口
Result := False;
end;
end;LoginExecute:
//打开登录窗口,并判断是否登录成功
function LoginExecute(aFormClass: TFormClass): Boolean;
begin
with aFormClass.Create(Application) do
begin
Logined := False;
try
ShowModal;
finally
free;
end;
result := Logined;
end;
end;
Project文件代码:
program Client;uses
Forms,
frmClient in 'frmClient.pas' {ClientForm},
u_public in 'u_public.pas',
uSerCfg in 'uSerCfg.pas' {ConfgForm},
uLogin in 'uLogin.pas' {LoginForm};{$R *.res}begin
Application.Initialize;
Application.Title := '轨道交通资料管理客户端';
Application.CreateForm(TConfgForm, ConfgForm);
Application.CreateForm(TLoginForm, LoginForm);
Application.CreateForm(TClientForm, ClientForm);
Application.Run;
end.主窗口创建时的代码:
procedure TClientForm.FormCreate(Sender: TObject);
begin
if not ConnectAppServ then
Application.Terminate; //如果未连接应用服务器,就退出应用程序。
ConfgForm.close;
if not LoginExecute(TLoginForm) then //如果身份验证无效,就退出系统
Application.Terminate;
end;ConnectAppServ:
function ConnectAppServ: boolean; //判断是否连接上了应用服务器
var
vs_Host, vs_Address, vs_Port: string;
reg: TRegistry;
begin
Result := True;
reg := Tregistry.create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
ClientForm.SocketConnection1.Connected := false;
//读取注册表配置的应用服务器信息
if Reg.OpenKey('\Software\物资管理', False) then
begin
vs_Host := reg.ReadString('Host');
vs_Address := reg.ReadString('Address');
vs_Port := reg.readstring('Port');
try
//测试连接
with ClientForm do
begin
SocketConnection1.Address := vs_Address;
SocketConnection1.Host := vs_Host;
SocketConnection1.Port := strtoint(vs_Port);
SocketConnection1.Connected := true;
end;
reg.closekey;
except //未连接上,弹出配置窗口
reg.closekey;
if not ConfgExecute(TConfgForm) then
Result := False;
end;
end
else
begin
if not ConfgExecute(TConfgForm) then //如果没有注册信息,弹出配置窗口
Result := False;
end;
end;LoginExecute:
//打开登录窗口,并判断是否登录成功
function LoginExecute(aFormClass: TFormClass): Boolean;
begin
with aFormClass.Create(Application) do
begin
Logined := False;
try
ShowModal;
finally
free;
end;
result := Logined;
end;
end;
Application.Terminate; //如果未连接应用服务器,就退出应用程序。
ConfgForm.close;
if not LoginExecute(TLoginForm) then //如果身份验证无效,就退出系统
Application.Terminate;
----
跟踪一下,这两个函数是不是有一个返回false