假设我现在已经又一个窗体Form1我想在程序中创建新的Form2应该怎么做呢?是使用Create()吗?窗体的show 方法和 showmodal 又什么区别呢?我应该怎么区分他们呢?小弟我用DELPHI做了一个简单的登陆窗口,当在EdtID中输入员工号(也就是ADOTable1所连接的表中ID字段)第一条记录还可以,可是如果第一次登陆输入后面的员工号(比如表中的第2条记录,第3条记录)就弹出“不存在该员工号!”敬请高手帮助!不知道我讲清楚了没有啊!我在线,敬请回!!!
procedure TFormLogin.BtnOKClick(Sender: TObject);
begin
adotable1.Open;
if EdtID.Text='' then
showmessage('请您输入员工号!')
else if (EdtID.Text = trim(adotable1.FieldByName('STF_ID').AsString))
and (EdtPSWD.Text=trim(adotable1.fieldbyname('PWD').AsString)) then
begin
if not adotable1.Eof then
adotable1.Next;
showmessage('正确的员工号!');
form2.showmodal;
EdtID.Text:=trim(adotable1.FieldByName('STF_ID').AsString);
end
else
showmessage('不存在该员工号!');
EdtID.Text:='';
EdtPSWD.Text:='';
EdtID.SetFocus;
end;
procedure TFormLogin.BtnOKClick(Sender: TObject);
begin
adotable1.Open;
if EdtID.Text='' then
showmessage('请您输入员工号!')
else if (EdtID.Text = trim(adotable1.FieldByName('STF_ID').AsString))
and (EdtPSWD.Text=trim(adotable1.fieldbyname('PWD').AsString)) then
begin
if not adotable1.Eof then
adotable1.Next;
showmessage('正确的员工号!');
form2.showmodal;
EdtID.Text:=trim(adotable1.FieldByName('STF_ID').AsString);
end
else
showmessage('不存在该员工号!');
EdtID.Text:='';
EdtPSWD.Text:='';
EdtID.SetFocus;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
form2:=tform2.Create(self);
form2.ShowModal ;
form2.Free;
end;end.
两者的区别是:用Show时,焦点可以转到别的窗体上,用Showmedol只能在本窗上操作。
。没有找到用户是因为你没有用循环,你用If怎么可能呢,表里的记录不会循环到最后有
要用For或While循环才可以的
qry.sql.text='select *from 你的表名 where STF_ID='''+edtid.text+''' and pas='''+edtpas.text+'''';
qry.open;
if qry.bof and qry.eof then
showmessage('登陆不成功')
else
form2.show;
用一个查询控件就行了.劝你看看书
application.createform(tform2,form2);
form2.show;這只是把窗體show出來而已並取得焦點.
form2.showmodal;是把窗體的焦點鎖在這個form2上.
如果不關掉form2那焦點就一直在form2上.
登入窗口最好是用一個combobox,edit兩個來搭配.
在登入窗口show事件寫
adoquery1.sql.clear;
adoquery1.sql.add('...');
adoquery1.ExecSQL;
adoquery1.active:=true;
combobox1.items.clear;
while not adoquery.eof do
combobox1.items.add(adoquery1.fieldbyname('用戶名').asstring);
adoquery1.next;
end;
這樣combobox1.text就可以先擇所有的用戶名.
其它我就不多說了