RobS
RobS

Reputation: 3857

Setting default properties of custom control

I've written a control descended from TCustomEdit but am having trouble changing the default size of the component from that defined in StdCtrls (i.e. width=121, height=21).

So in Create I have:

inherited Create(AOwner);
width:=40;
height:=20;

But when the control is placed on the form it is drawn with the default width and height for TCustomEdit. I've reduced the test case to a simple component that merely has the constructor above and nothing else. I've also tried setting autosize:=false in the constructor but no joy.

From searching around I think I'm doing the right thing but plainly it's not working. How to I get the behaviour I'm after?

Upvotes: 1

Views: 896

Answers (1)

jpfollenius
jpfollenius

Reputation: 16620

That works for me (XE2). Make sure your constructor is marked override so that it is actually called:

constructor Create(AOwner : TComponent); override;

This is necessary because TComponent has a virtual constructor.

Upvotes: 4

Related Questions