Delphi, at design-time, what is the state of ComponentState, ControlState when created with a nil owner?

Viewed 562

If a function is executed at design-time, and creates a TComponent / TControl descendant with a nil owner, the following code in System.Classes will not call InsertComponent:

constructor TComponent.Create(AOwner: TComponent);
begin
  FComponentStyle := [csInheritable];
  if AOwner <> nil then AOwner.InsertComponent(Self);
end;

As such, our new object will not inherit ComponentState. What happens to conditions that rely on the csDesigning flag for this component?

if csDesigning in ComponentState
1 Answers

The condition would render False.

That means for you as component builder that when you apparently intentionally create a (sub-)component without an owner, any reliance on whether that component is being designed by an end user simply should not exist. If it does, you would have to implement a custom "is designing"-state system, but then you better should redesign your requirements.

For overriden components you could call the protected SetDesigning method yourself.

This all assumes that you are fully aware of creating designtime sub-components without owner generally should be prevented unless you have very compelling reasons not to. Remember that components on the component pallete always should follow the default owner-mechanism.

Related