现要打开一个模态对话框,以让用户输入一个名称。
在对话框中,Button1是默认按钮.有一个文本框,需要在关闭之前检查文本框是否为空.
我现在想到的是在Button1的Click事件中检查,代码如下:
procedure TdlgUserName.Button1Click(Sender: TObject);
var
theName:String;
begin
theName:=Edit1.Text;
//检查是否为空
if theName='' then
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
end
else
begin
//Utils.CheckDBUserName用于检查数据库是否已存在该用户名
if Utils.CheckDBUserName(theName) then //不存在,可以继续
begin
//记入一个property中,然后
...
ModalResult:=mrOK;
end
else
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
end;
end;
end;在主Form中调用它如下:
....
dlg.Create(Self);
if dlg.ShowModal=mrOK then
//...插入用户名到数据库
....但是运行结果显示,在Button1的Click事件中检查后,无论合法如否,窗口都关闭了.
没有达到预想的效果.
请问,应该在什么地方进行检查?怎么做?谢谢!
随时揭帖.
在对话框中,Button1是默认按钮.有一个文本框,需要在关闭之前检查文本框是否为空.
我现在想到的是在Button1的Click事件中检查,代码如下:
procedure TdlgUserName.Button1Click(Sender: TObject);
var
theName:String;
begin
theName:=Edit1.Text;
//检查是否为空
if theName='' then
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
end
else
begin
//Utils.CheckDBUserName用于检查数据库是否已存在该用户名
if Utils.CheckDBUserName(theName) then //不存在,可以继续
begin
//记入一个property中,然后
...
ModalResult:=mrOK;
end
else
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
end;
end;
end;在主Form中调用它如下:
....
dlg.Create(Self);
if dlg.ShowModal=mrOK then
//...插入用户名到数据库
....但是运行结果显示,在Button1的Click事件中检查后,无论合法如否,窗口都关闭了.
没有达到预想的效果.
请问,应该在什么地方进行检查?怎么做?谢谢!
随时揭帖.
解决方案 »
- 有没有人用过idhttp?如何提交aspx页的viewstate表单值啊?
- 百钱买百鸡的问题,已经计算出第一种可能,我想再显示下一组的可能情况
- 晒晒得意小作品,delphi仿bubble breaker的PC中文版游戏,扩展存档分享排名功能
- 怎样给软件加上试用期,并在试用期后要求注册?
- DBGRIDEH问题
- 我写了一个 类 如何发布为 dcu 控件安装包 ?
- 一个label的 Capion属性内容中 怎样设置 不同的字体与颜色 谢谢!
- fastreport打印的问题?
- 用ado插入数据时出现的问题
- SOS :如何加载一个图象文件显示到form的客户区中:?????
- 关于InstallShield的打包问题
- reset(var f:file;[; recsize:word] )函数的用法
var
theName:String;
begin
theName:=Edit1.Text;
//检查是否为空
if theName='' then
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
Exit; <<----------------------------------------
end
else
begin
//Utils.CheckDBUserName用于检查数据库是否已存在该用户名
if Utils.CheckDBUserName(theName) then //不存在,可以继续
begin
//记入一个property中,然后
...
ModalResult:=mrOK;
end
else
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
Exit; <<------------------------------------------
end;
end;
end;在主Form中调用它如下:
....
dlg.Create(Self);
if dlg.ShowModal=mrOK then
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
Exit;//加入这一句,或者不要把button1修改为模态按钮/
end;
界面不友好啊,
没有好的方法吗?
在对话框中,Button1是默认按钮.有一个文本框,需要在关闭之前检查文本框是否为空.
我现在想到的是在Button1的Click事件中检查,代码如下:
procedure TdlgUserName.Button1Click(Sender: TObject);
begin
if trim(edit1.text)='' then
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
end
else
begin
//Utils.CheckDBUserName用于检查数据库是否已存在该用户名
if Utils.CheckDBUserName(theName) then //不存在,可以继续
begin
//记入一个property中,然后
...
ModalResult:=mrOK;
end
else
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
end;
end;
end;
begin
Application.MessageBox('用户名不能为空','Alert');
Edit1.SetFocus;
abort;//加上这个就行了
end