xaid
xaid

Reputation: 750

Making an editable designtime component for Delphi

I've been searching the whole internet for an answer but I cant find one.

What I want to do is to create a component that I, in design time, can add components to, move them around, right click on them to pop up a menu, change their properties, etc etc.

Like, for instance, I drop my component "A" (which is based on TImage32 from the Graphics32 library), and then I want to be able to drop a component "B" (which is based on TBitmap32) in to A, but since B is not inherited from a standard VCL like TPanel I dont know how to make a design time component.

Upvotes: 0

Views: 688

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

What you are searching for is the ability to create a parent/child relationship. The parent acts as a container and the child is contained within the bounds of the container. A TPanel is a classic example of a container. Any visual component can be a child.

In terms of ancestry the parent must be derived from TWinControl and the child must be derived from TControl. In practice you seldom derive from these classes directly, rather from one of their descendents. The other factor, if I recall correctly, is that the parent control must include csAcceptsControls in its ControlStyle.

Now, TImage32 does indeed derive from TWinControl and so it can act as a container. However, I am not sure whether or not csAcceptsControls is included in the ControlStyle for TImage32.

I'm really not familiar with TImage32 and don't know whether or not it can act as a parent. I have a suspicion that it is not designed to act as a container. If that is the case then you can add csAcceptsControls to the ControlStyle in the constructor of your derived class and have the control act as a parent.

I suspect that if TImage32 does not include csAcceptsControls then this is by design and the image control is not expected to act as a parent.

Apparently TImage32, unlike the VCL TImage, is indeed capable of acting as a parent to other controls.

As for the other control in your question, TBitmap32 is not derived from TControl and cannot be a child control.

Upvotes: 2

Related Questions