构造函数(50分)

  • 主题发起人 主题发起人 hly
  • 开始时间 开始时间
H

hly

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在form的构造函数中加入参数
constructor Create(AOwner: TComponent;i:integer); overload;

constructor TForm2.Create(AOwner: TComponent;i:integer);
begin
inherited create(AOwner);
Case i of
0 : begin end;
1 : begin end;
end;
end;
但是程序调用showmodal就抱错,为什么呢???
 
从代码中找不出错误,试试
constructor Create(AOwner: TComponent;i:integer);reintroduce;overload;
 
把“overload;”去掉,没有这个原型,不需要覆盖。
 
没问题的呀。
最好把form2的自动创建窗体去掉.project->options->....中
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
try
form2:=Tform2.create(self,1);
form2.ShowModal;
finally
form2.Free;
end;
end;

end.

////////////////
unit Unit2;

interface

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

type
TForm2 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
fi:integer;
public
{ Public declarations }
constructor Create(AOwner: TComponent;i:integer); overload;
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

{ TForm2 }

constructor TForm2.Create(AOwner: TComponent; i: integer);
begin
inherited create(AOwner);
Case i of
0 :
begin
fi:=0;
end;
1 :
begin
fi:=1;
end;
end;
end;


procedure TForm2.FormCreate(Sender: TObject);
begin
label1.Caption:=inttostr(fi);
end;

end.

 
to jbas
你的程序我编译通过了,很奇怪,我写的和你的一模一样
可能是我的d5有问题,谢谢你的回答
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部