Delphi中的创建一个窗体的有关问题
Delphi中的创建一个窗体的问题
在一个程序中,创建了两个窗体,分别为Form1和Form2,在Project->Options->Forms中将Form1设置为自动显示,而Form2设置为非自动显示。
我想在Form1中添加一个按钮,点击按钮会重新创建Form2,我用的是以下方法:
首先在Form1中的unit Unit1 ;下一行添加添加unit Unit2 ;
然后在Form1中的implementation的下一行添加uses Unit2;
最后点击Form1中的Button1,写入代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
end;
编译后出现下面两个错误:
[DCC Error] Unit1.pas(2): E2029 'INTERFACE' expected but 'UNIT' found
[DCC Fatal Error] 调用DLL.dpr(6): F2063 Could not compile used unit 'Unit1.pas'
这错误是怎么回事啊,刚看几天Delphi对这样的问题,不太明白,特来请教各位高手大哥大姐们!
以前用BCB感觉非常简单,添加以下头文件,然后
TForm *frm=new TForm2(Application);
frm->ShowModal();
就搞定了,用Delphi就搞不了了
------解决方案--------------------
------解决方案--------------------
在interface下的uses加 Unit2
在一个程序中,创建了两个窗体,分别为Form1和Form2,在Project->Options->Forms中将Form1设置为自动显示,而Form2设置为非自动显示。
我想在Form1中添加一个按钮,点击按钮会重新创建Form2,我用的是以下方法:
首先在Form1中的unit Unit1 ;下一行添加添加unit Unit2 ;
然后在Form1中的implementation的下一行添加uses Unit2;
最后点击Form1中的Button1,写入代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
end;
编译后出现下面两个错误:
[DCC Error] Unit1.pas(2): E2029 'INTERFACE' expected but 'UNIT' found
[DCC Fatal Error] 调用DLL.dpr(6): F2063 Could not compile used unit 'Unit1.pas'
这错误是怎么回事啊,刚看几天Delphi对这样的问题,不太明白,特来请教各位高手大哥大姐们!
以前用BCB感觉非常简单,添加以下头文件,然后
TForm *frm=new TForm2(Application);
frm->ShowModal();
就搞定了,用Delphi就搞不了了
------解决方案--------------------
unit Unit1;
interface
uses
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;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
//»òÕß
//Form2 := TForm2.Create(Application);
Form2.Show;
end;
end.
------解决方案--------------------
在interface下的uses加 Unit2