Ad Space — Top Banner

Control Has No Parent Window

Delphi Programming Language

Severity: Moderate

What Does This Error Mean?

This error means a VCL windowed control tried to create its Windows HWND handle but has no parent window to attach to. Every windowed control in Windows must have a parent window — without one, Windows cannot create the control. The fix is to set the Parent property before the control needs its handle, or to create the control after its parent exists.

Affected Models

  • Delphi 10.4 Sydney
  • Delphi 11 Alexandria
  • Delphi 12 Athens
  • Embarcadero RAD Studio
  • Free Pascal / Lazarus

Common Causes

  • Creating a TWinControl descendant dynamically and not setting its Parent property
  • Creating a control in a data module or non-visual context where no parent form is available
  • Setting a control's Parent to nil after creation and then forcing handle creation
  • Creating controls in a background thread where the main form is not accessible
  • Calling HandleNeeded or Show on a control before assigning its Parent

How to Fix It

  1. After creating a control dynamically, immediately set its Parent property: MyButton := TButton.Create(Self); MyButton.Parent := Self; — where Self is the form or a container on the form.

    The Parent determines where the control is displayed. Without Parent, the control has no visual home.

  2. Understand the difference: Owner is who frees the control when done (usually the form). Parent is what the control is drawn on (also usually the form, or a panel/group box on the form).

    It is common and correct to set both: TButton.Create(Self) makes Self the owner, and MyButton.Parent := Self makes Self the parent too.

  3. If creating controls before the main form is shown, defer creation to the FormCreate or FormShow event rather than in a unit's initialization section or a global variable initializer.

    At program startup, the main form does not exist yet until Application.CreateForm runs. Any control creation before that has no form to use as parent.

  4. For controls created in a non-form class (like a data module), pass the form as a parameter and use it as the parent: MyControl.Parent := AForm;

    Data modules have no visual surface. Controls cannot use a data module as their parent — they need a TWinControl descendant.

  5. Never create VCL controls in background threads. All VCL operations including control creation must happen on the main thread. Use TThread.Synchronize or TThread.Queue to create controls on the main thread.

    Creating controls off the main thread causes handle-related errors including 'Control has no parent window'.

When to Call a Professional

This error is almost always caused by forgetting to set the Parent property after dynamically creating a control. Every dynamically created windowed control needs: Owner (for memory management) and Parent (for display). Owner and Parent are separate concepts in Delphi — setting Owner does not automatically set Parent.

Frequently Asked Questions

Why does a TLabel not need a parent window in the same way?

TLabel is a TGraphicControl, not a TWinControl — it does not have its own Windows HWND. TLabel draws itself on its parent's device context instead. However, TLabel still needs a Parent property set so it knows which control's surface to draw on — you will still get errors if Parent is nil.

What is the difference between Owner and Parent in Delphi?

Owner is a memory management concept — when the Owner is freed, it frees all components it owns. Parent is a visual concept — the Parent is the windowed control that contains and displays the child control. A button on a form is owned by the form (for cleanup) and parented to the form (for display), but you can have different owners and parents.

Can I create a form with no parent?

Yes. Top-level forms (TForm) do not require a parent — Windows allows top-level windows without parent windows. The 'Control has no parent window' error applies to controls placed inside forms (buttons, edits, panels), not to forms themselves. Forms use the Application.Handle or 0 as their Windows parent, which is handled automatically by Delphi.