有没有可能将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. 请问在DBgrid中如何不显示SQL数据表中日期时间型字段的日期部分 高手请帮忙,这种查询怎么做? 誰有RS232通訊組件呀,能不能給我發一個呀(d5,d6的),dll的帶說明文檔的也可。 [求助]delphi开发ocx的大致步骤 怎么恢复IE? 请教高手:关于用TStrings作为函数返回值的问题!! 如何得到某个字符串的bitmap?急急急!!! 做监控员工上班时间是否上QQ项目 谁能帮帮啊,实在解决不了 有关串口控制?来者必结分!!! 如何制作半透明的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.