program Project1;uses Forms, Unit1 in 'Unit1.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2};{$R *.RES}begin Application.Initialize; Application.CreateForm(TForm1, Form1); Form2:=TForm2.create(Application); if Form2.ShowModal=1 then //当form2返回值为mrok时,应用程序运行 begin Application.Run; end else exit; end.
感谢您及时回复,在FORM2中的BUTTONCLICK是否应该这样创建啊? if 成功 then ModalResult:=mrok else ModalResult:=mrno; 可是我创建的FORM2不管成功失败都显示FORM1了啊?
to angle097113(深思不解) 那样的话FORM1最小化时就显示在任务栏的左下方了,而不是显示在任务栏上,我第一次就是这么做的。
给你一段代码吧: procedure Tfrm_load_n.SpeedButton1Click(Sender: TObject); begin if ( edt_uses.Text = '' ) and ( edt_pwd.Text = '' ) then begin Showmessage('请登陆!'); edt_uses.SetFocus; end else begin DataModule1.adoqry_load_mx.Close; DataModule1.adoqry_load_mx.open(); DataModule1.adoqry_load_mx.First(); while not DataModule1.adoqry_load_mx.Eof do begin if ( DataModule1.adoqry_load_mx.FieldByName('FName').AsString = edt_uses.Text ) and ( DataModule1.adoqry_load_mx.FieldByName('pwd').AsString = edt_pwd.Text ) then begin Close(); exit; end else begin DataModule1.adoqry_load_mx.Next(); end; end; edt_uses.Text := ''; edt_pwd.Text := ''; edt_uses.SetFocus; MessageDlg('密码错误!',mtError,[mbOK],0); end; end;
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};{$R *.RES}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Form2:=TForm2.create(Application);
if Form2.ShowModal=1 then //当form2返回值为mrok时,应用程序运行
begin
Application.Run;
end
else
exit;
end.
if 成功 then
ModalResult:=mrok
else
ModalResult:=mrno;
可是我创建的FORM2不管成功失败都显示FORM1了啊?
那样的话FORM1最小化时就显示在任务栏的左下方了,而不是显示在任务栏上,我第一次就是这么做的。
Form2:=TForm2.create(self);
Form2:=TForm2.create(nil);
三者有什么区别,各用在什么情况下?
loginform.showmodal
或者动态的
try
loginform:=tloginform.create(application);
loginforn.showmodal;
except
loginform.free;
那么你在form1的onclose事件里
action:=cafree;
procedure Tfrm_load_n.SpeedButton1Click(Sender: TObject);
begin if ( edt_uses.Text = '' ) and ( edt_pwd.Text = '' ) then
begin
Showmessage('请登陆!');
edt_uses.SetFocus;
end
else
begin
DataModule1.adoqry_load_mx.Close;
DataModule1.adoqry_load_mx.open();
DataModule1.adoqry_load_mx.First();
while not DataModule1.adoqry_load_mx.Eof do
begin
if ( DataModule1.adoqry_load_mx.FieldByName('FName').AsString = edt_uses.Text ) and ( DataModule1.adoqry_load_mx.FieldByName('pwd').AsString = edt_pwd.Text ) then
begin
Close();
exit;
end
else
begin
DataModule1.adoqry_load_mx.Next();
end;
end;
edt_uses.Text := '';
edt_pwd.Text := '';
edt_uses.SetFocus;
MessageDlg('密码错误!',mtError,[mbOK],0);
end;
end;