有没有可能将Create的参数增加?? 一般都是Create(AOwner:TComponent)一个AOWner参数,有没有可能增加一个或两个参数,因为我在建立类时有可能根据不同情况,新建出来的类的外观等根据参数会有所不同。这种情况除了在Create里加参数,还有没有别的办法?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要自己通过继承产生一个新的控件才可以,比如:TMyButton= class(TButton);private fColor: TColor;public constructor Create(AOwner: TComponent; Color: TColor); override;end;constructor TMyButton.Create(AOwner: TComponent; Color: TColor);begin Inherited Create(AOwner); fColor:=Color;end;这样新控件就有了新的参数了。 应该用reintroduce来覆盖原来的构造函数。但是这样一来,你的控件就无法在设计时进行编辑……因为IDE是无法自动调用你的新构造函数的。实际上并不推荐这么用,完全可以用其他的方法来初始化数据。比如自己定义一个事件,在构造函数中回调就行了。 在类里面重定(overload)一个create事件也可以的啊,你想把参数怎么变就怎么变 不可以的,要想自定义参数类型及个数,只有从TObject继承才行 使用constructor 作一个析构 使用自定参数的Constructor只能手动创建!对此Delphi IDE无能为力。citytramper(阿琪)的方法也是行的通的。对于可视控件,请尽量避免修改构造函数的参数结构。 要inHerit父类的建构函数,要保留Owner参数传递。除此之外没有多少好说的。同意 jufeng_zhu(老猪) overload就可以了啊然后再inherited Create(将原来create的参数传到这里); 我那天就是这么做的,可是还是不行呀,应该是jufeng_zhu(老猪)的方法。unit ddgRunButton;interfaceuses SysUtils, Classes, Controls,StdCtrls,Buttons;type TddgRunButton = class(TWinControl) private FEdit:TEdit; FSpeedButton:TSpeedButton; protected procedure SetText(Value:string); function GetText:string; public ///////////////declaration of 'Create' differ from previous declaration//////// constructor Create(AOwner:TComponent;BillType:integer);override; published property Text:string read GetText write SetText; end;procedure Register;implementationprocedure Register;begin RegisterComponents('DDG', [TddgRunButton]);end;constructor TddgRunButton.Create(AOwner:TComponent;BillType:integer);begin inherited Create(AOwner); FEdit:=TEdit.Create(Self); FEdit.Parent:=Self; FEdit.Height:=21; FSpeedButton:=TSpeedButton.Create(Self); FSpeedButton.Parent:=Self; FSpeedButton.Left:=FEdit.Width; FSpeedButton.Height:=19; FSpeedButton.Width:=19; FSpeedButton.Caption:='...'; FSpeedButton.Parent:=Self;end;procedure TddgRunButton.SetText(Value:string);begin FEdit.Text:=Value;end;function TddgRunButton.GetText:string;begin Result:=FEdit.Text;end;end.这句出错constructor Create(AOwner:TComponent;BillType:integer);override; ///////////////declaration of 'Create' differ from previous declaration//////// 在实现部分就不要加override了。。 可以在写完方法声明后,SHIFT+CTRL+C,类完成功能,自动生成实现部分。。 应该用reintroduce和overload程序:unit BillHead;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxMaskEdit, cxButtonEdit, cxDBEdit, StdCtrls, cxControls, cxContainer, cxEdit, cxTextEdit;type TBillHead = class(TFrame) cxDBTextEdit1: TcxDBTextEdit; private { Private declarations } public constructor Create(AOwner:TComponent;BillType:integer);reintroduce;overload; end;implementation{$R *.dfm}{ TBillHead }constructor TBillHead.Create(AOwner:TComponent;BillType:integer);begin inherited Create(AOwner); showmessage(inttostr(Billtype));end;end. 关于delphi调用vc编写的dll中参数类型问题 增加相应记录的问题! 哪位朋友有delphi7入门教材? 新手问题!有点不好意思问! 有人能告诉我用DELPHI写一个计算机器程序的源程序吗? 如何读写文本文件? 搜了一晚上,但还没找到一个正确的取消共享文件夹的办法?netsharedel需要引用什么?谢谢! 请问Tdatetimepicker控件在那 如何设置超时??求救,急!!! delphi编写PC程序后,如何加入服务启动? 如何制作半透明的form 请教大家怎样编程实现两个不同局域网内的单机通信?
TMyButton= class(TButton);
private
fColor: TColor;
public
constructor Create(AOwner: TComponent; Color: TColor); override;
end;constructor TMyButton.Create(AOwner: TComponent; Color: TColor);
begin
Inherited Create(AOwner);
fColor:=Color;
end;这样新控件就有了新的参数了。
citytramper(阿琪)的方法也是行的通的。对于可视控件,请尽量避免修改构造函数的参数结构。
要保留Owner参数传递。除此之外没有多少好说的。同意 jufeng_zhu(老猪)
然后再
inherited Create(将原来create的参数传到这里);
SysUtils, Classes, Controls,StdCtrls,Buttons;type
TddgRunButton = class(TWinControl)
private
FEdit:TEdit;
FSpeedButton:TSpeedButton;
protected
procedure SetText(Value:string);
function GetText:string;
public
///////////////declaration of 'Create' differ from previous declaration////////
constructor Create(AOwner:TComponent;BillType:integer);override; published
property Text:string read GetText write SetText;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('DDG', [TddgRunButton]);
end;constructor TddgRunButton.Create(AOwner:TComponent;BillType:integer);
begin
inherited Create(AOwner);
FEdit:=TEdit.Create(Self);
FEdit.Parent:=Self;
FEdit.Height:=21; FSpeedButton:=TSpeedButton.Create(Self);
FSpeedButton.Parent:=Self;
FSpeedButton.Left:=FEdit.Width;
FSpeedButton.Height:=19;
FSpeedButton.Width:=19;
FSpeedButton.Caption:='...';
FSpeedButton.Parent:=Self;
end;procedure TddgRunButton.SetText(Value:string);
begin
FEdit.Text:=Value;
end;
function TddgRunButton.GetText:string;
begin
Result:=FEdit.Text;
end;end.这句出错
constructor Create(AOwner:TComponent;BillType:integer);override;
///////////////declaration of 'Create' differ from previous declaration////////
程序:
unit BillHead;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxMaskEdit, cxButtonEdit, cxDBEdit, StdCtrls, cxControls,
cxContainer, cxEdit, cxTextEdit;type
TBillHead = class(TFrame)
cxDBTextEdit1: TcxDBTextEdit;
private
{ Private declarations }
public
constructor Create(AOwner:TComponent;BillType:integer);reintroduce;overload;
end;implementation{$R *.dfm}{ TBillHead }constructor TBillHead.Create(AOwner:TComponent;BillType:integer);
begin
inherited Create(AOwner);
showmessage(inttostr(Billtype));end;end.