Recent

Author Topic: Error: Control " has no parent window  (Read 9328 times)

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Error: Control " has no parent window
« on: October 18, 2016, 05:09:37 pm »
Hello,

I have a doubt, in Lazarus's program it shows me occasionally the mistake:

Control '' has no parent window.

Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

There is some way of obtaining more precisely to which it refers? it happens on runtime.
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Error: Control " has no parent window
« Reply #1 on: October 18, 2016, 05:14:09 pm »
There is some way of obtaining more precisely to which it refers? it happens on runtime.
Run your program through the debugger. There is no way of telling without seeing some actual code.

Most likely reason would be that you created components/forms dynamically but forgot to set the owner/parent. But that is pure speculation.
« Last Edit: October 18, 2016, 05:15:41 pm by molly »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Error: Control " has no parent window
« Reply #2 on: October 18, 2016, 05:16:02 pm »
There is some way of obtaining more precisely to which it refers? it happens on runtime.

Make sure you give all your GUI controls (including those created dynamically) a unique Name.
Then you'll find such error messages far more informative.
BTW, one common cause of this sort of error arises through trying to access a control's Canvas before it has been assigned a Parent.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Error: Control " has no parent window
« Reply #3 on: October 18, 2016, 07:28:08 pm »
BTW, one common cause of this sort of error arises through trying to access a control's Canvas before it has been assigned a Parent.

Or any HWND-based property, for that matter.  If a property requires the control to have a valid HWND, but it does not have a Parent, or its Parent does not have a Parent, or so on, then the HWND cannot be created, and the property fails.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: Error: Control " has no parent window
« Reply #4 on: October 19, 2016, 02:26:05 pm »
Thanks for the responses.
 :)
The program is simple enough, has few components these and the mistake happens of random form suddenly only often.
There are no dynamic components only components created directly in the form.

Formulario_Indice: TFormulario_Indice
    Panel: TGroupBox
    Arbol_Indice: TTreeView
    BitBtn_Salir: TBitBtn
    BitBtn_Salvar_A_Fichero: TBitBtn
    Etiqueta_Busqueda: TLabel
    Editor_Busqueda: TEdit
    BitBtn_Expandir_Ramas: TBitBtn
    BitBtn_Contraer_Ramas: TBitBtn
    BitBtn1: TBitBtn
    ListadoImagenes: TImageList
    Dialogo_Salvar_Fichero: TSaveDialog
    IconoBandeja: TTrayIcon
    MenuEmergente: TPopupMenu
         Maximizar: TMenuItem
         Salir: TMenuItem

I will try commenting on components to seeing if annulling someone of it eliminates the message.
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Error: Control " has no parent window
« Reply #5 on: October 20, 2016, 05:22:09 am »
The program is simple enough, has few components these and the mistake happens of random form suddenly only often.
There are no dynamic components only components created directly in the form.

Generally speaking, you should not be seeing this kind of error for components that are streamed from design-time to run-time.  This usually only happens if you are creating components dynamically in code at run-time and are misusing them.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: Error: Control " has no parent window
« Reply #6 on: June 15, 2021, 09:39:09 am »
This is an old thread, but I have the same problem. There is no dynamic component involved in any way. I get this error at design time when trying to opening a specific form in the IDE. The form worked allright say one week ago, no changes.

Lazarus 2.0.12 on Windows 10.

Right now I am looking for corruption issues in the lfm, but at first glance the lfm seems OK, hard to tell though, it's a quite big form...

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: Error: Control " has no parent window
« Reply #7 on: June 16, 2021, 02:35:21 pm »
I finally found the problem. This seems to be one of those rare cases when multiple small effects work together and create a big mess.

in my case, I had a TFrame embedded in a TForm containing a TVirtualStringTree. Somehow, in the frame source file (.lfm) in the definition of the TFrame the following property got set:

Code: Pascal  [Select][+][-]
  1. ParentFont = True

At design time, a Frame doesn't have a parent, hence the problem.

I also found out that there is some recursion/inheritance behaviour, sometimes (not always!) setting this property in a subcomponent (a TVirtualStringTree) contained inside the frame would give the same messages and crashes.

There must be more to this however, because if you try to set ParentFont to True using the IDE in the current Lazarus version (2.0.12), it won't accept it, you may set it in the GUI, but as soon as you save the frame the property gets silently reset to False. However, there must be a code path around this, since in my lfm source file this property was set to True. For my testing I fell back to modifying the .lfm using a text editor.

More experiments with this property revealed alarming behaviour of the IDE, the effects of this property (and probably similar other properties) beeing set were all sorts of arbitrary crashes of the IDE, sometimes vaguely pointing into the right direction, but most often not.

May this help someone in the future, so the two development days wasted on this issue may be beneficial to someone else.

Armin.   

« Last Edit: June 16, 2021, 02:40:09 pm by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

 

TinyPortal © 2005-2018