constructor create窗体类的 构造函数
通常很少对窗体类TForm 添加构造函数,一般类会经常用到;
同事需要创建窗体是先传特殊参数。写法:
public constructor create(int:Integer;flag:Boolean;AOwner:TComponent); constructor TForm2.create(int: Integer; flag: Boolean;AOwner:TComponent); begin //ShowMessage('fdasfdsaf'); inherited create(AOwner); //调用父类构造函数,方可以调用到子类的 回调函数 procedure TForm2.FormCreate(Sender: TObject); Fint :=int; FFlag :=flag; end;
代码如下:
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm2 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } Fint:Integer; FFlag:Boolean; public constructor create(int:Integer;flag:Boolean;AOwner:TComponent); { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} constructor TForm2.create(int: Integer; flag: Boolean;AOwner:TComponent); begin //ShowMessage('fdasfdsaf'); inherited create(AOwner); Fint :=int; FFlag :=flag; end; procedure TForm2.FormCreate(Sender: TObject); begin ShowMessage('TForm2.FormCreate'); ShowMessage(IntToStr(Fint )); end; end.
调用:
procedure TForm1.btn1Click(Sender: TObject); var frm2:TForm2; begin frm2:=TForm2.create(5,true,Self); frm2.Show; end;
拓:貌似这篇写得还不错:http://blog.sina.com.cn/s/blog_4522f0b8010008s3.html

浙公网安备 33010602011771号