多态窗体,出错一问 ( 积分: 50 )

  • 主题发起人 主题发起人 chinaandys
  • 开始时间 开始时间
C

chinaandys

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit2;

interface

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

type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
constructor Create(Aowner:Tcomponent;S:String);override;
end;

var
Form2: TForm2;

implementation

{$R *.dfm}
constructor TForm2.Create(Aowner:Tcomponent;S:String);
begin
inherited Create(AOwner);
self.Caption:=s;
end;
end.
----------------------编译错误提示--------------------------
[Error] Unit2.pas(15): Declaration of 'Create' differs from previous declaration
[Fatal Error] Unit1.pas(22): Could not compile used unit 'Unit2.pas'
 
unit Unit2;

interface

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

type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
constructor Create(Aowner:Tcomponent;S:String);override;
end;

var
Form2: TForm2;

implementation

{$R *.dfm}
constructor TForm2.Create(Aowner:Tcomponent;S:String);
begin
inherited Create(AOwner);
self.Caption:=s;
end;
end.
----------------------编译错误提示--------------------------
[Error] Unit2.pas(15): Declaration of 'Create' differs from previous declaration
[Fatal Error] Unit1.pas(22): Could not compile used unit 'Unit2.pas'
 
构造方法不要 override
 
constructor Create(Aowner:Tcomponent;S:String);override;
换成:
constructor Create(Aowner:Tcomponent;);override;
“s“可在private中定义


 
应该声明两次啥!
public
constructor Create(AOwner: TComponent);overload; override;
constructor Create(AOwner: TComponent;......); reintroduce; overload;
end;
 
这个应该是
inherited Create(AOwner);
的问题
inherited ;就可以了
 
这样

type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
constructor Create;ovreload;
constructor Create(Aowner:Tcomponent;S:String);
end;
 
我上面说错了
这才是标准做法(有一个编译警告)
constructor Create(Aowner:Tcomponent;S:String);overload;
实现必须是这样:
constructor TForm2.Create(Aowner: Tcomponent; S: String);
begin
inherited create(Aowner);
//...
end;
 
同意上面的意见!
用overload;
 
由于窗体重载次次数比较多,所以感觉用OverLoad后,显示出现的太多了,各位高人还有什么高招,谢谢
 
显示出现的太多了
==========
是什么意思?
 
是不是觉得同名的构造器太多了.
不考虑兼容性,那你就给构造器起不同的名字.

constructor CreatebyString(Aowner:Tcomponent;S:String);
 

Similar threads

后退
顶部