delphi 打开新form的问题

lifenghe1984 2012-04-13 02:29:27
我在unit1里有一个form1 登录的
登录成功以后要运行unit2里的form2
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
unit2,Dialogs, StdCtrls, DB, ADODB;

type
TForm1 = class(TForm)

Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var
LoginCount: Integer;
begin

LoginCount := 0;
with ADOQuery1 do
begin
Close;

sql.Add('select * from users where id=:username');
parameters.ParamByName('username').Value :=trim(Edit1.Text );
open;
end;
if ADOQuery1.FieldByName('pwd').AsString =trim(Edit2.Text ) then
begin
Form1.Hide ;

Tform2.Show;

application.MessageBox('成功!','系统提示',0+64);

end
else
begin
application.MessageBox('密码或者用户名错误,请确认!','系统提示',0+64);

end;
end;

end.




但是 Tform2.Show; 这句报错 意思是找不到tform2
哪位指点指点啊
...全文
354 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn小虫 2012-07-19
  • 打赏
  • 举报
回复
Tform2是类呀
你要具体实例化一个Tform2的对象
jonathanscor 2012-04-13
  • 打赏
  • 举报
回复
看创建了没有,没有的话先创建,然后form.show
wzgdyn 2012-04-13
  • 打赏
  • 举报
回复 1
要在unit1里面引用unit2,然后创建form2
……
……
……
uses unit2;
……
……
form2:=Tform2.create(nil);
try
form2.showmodal;
finally
from2.free;
from2:=nil;
end;

……
……
……
寂小魔 2012-04-13
  • 打赏
  • 举报
回复
+1
[Quote=引用 1 楼 的回复:]

Tform2.Show;->form2.Show();
[/Quote]
NoMore 2012-04-13
  • 打赏
  • 举报
回复
Form2.showmodal;
ADSLAN 2012-04-13
  • 打赏
  • 举报
回复
同一楼 多了一个T
我看见佛 2012-04-13
  • 打赏
  • 举报
回复
Tform2.Show;->form2.Show();

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧