读书人

使用messagedlg时出现的有关问题

发布时间: 2012-03-03 15:33:04 作者: rapoo

使用messagedlg时出现的问题!
begin
i:=messagedlg( '无此用户名! ',mtinformation,[mbyes,mbno],1);
if i=2 then form1.Close
else form1.Visible:=false;//form1为主form
form5.Show;

end
这是登陆框的制做,在用户输入错误的用户名时可以重新回到登陆框,但是每次点击确定都会进入主form不知道为什么,即使把主form设置成不可见的也没有用.
如果还有更好的方法也希望大家能够告诉我,谢谢!

[解决办法]
感觉你的程序逻辑有些问题:

repeat
......
//显示用户登录界面, 完成用户检测的代码
......
if 检测用户通过 then break;
i := messagedlg( '无此用户名!是否重试? ', mtinformation, [mbyes,mbno], 1);
if i = mrNo then Application.Terminate;
until False;
form1.Visible := True;
[解决办法]
登录都不是这样写的。
program SyscanMakeCode;

uses
Forms,
Controls,
unitMain in 'forms\unitMain.pas ' {frmMain},
unitComm in 'unitComm.pas ',
unitDM in 'forms\unitDM.pas ' {DM: TDataModule},
unitLogon in 'forms\unitLogon.pas ' {frmLogon},
unitAbout in 'forms\unitAbout.pas ' {frmAbout};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TDM, DM);
frmLogon := TfrmLogon.Create(Application);
try
frmLogon.ShowModal;
if frmLogon.ModalResult = mrOk then
begin
Application.CreateForm(TfrmMain, frmMain);
Application.Run;
end;
finally
frmLogon.Free;
end;

end.

读书人网 >.NET

热点推荐