To change default property values and initialize owned classes for your component, you must override the inherited constructor and destructor. In both cases, remember always to call the inherited method in your new constructor or destructor.
The default size of a graphic control is fairly small, so you can change the width and height in the constructor. Changing default property values is explained in more detail in Modifying an existing component.
type TSampleShape = class(TGraphicControl) public { constructors are always public } constructor Create(AOwner: TComponent); override { remember override directive } end;
class PACKAGE TSampleShape : public TGraphicControl { public: virtual __fastcall TSampleShape(TComponent *Owner); };
type TSampleShape = class(TGraphicControl) . . . published property Height default 65; property Width default 65; end;
class PACKAGE TSampleShape : public TGraphicControl { . . . __published: __property Height; __property Width; }
constructor TSampleShape.Create(AOwner: TComponent); begin inherited Create(AOwner); { always call the inherited constructor } Width := 65; Height := 65; end;
__fastcall TSampleShape::TSampleShape(TComponent* Owner) : TGraphicControl(Owner)
{
Width = 65;
Height = 65;
}
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|