2

I've been tasked with supporting an application that is written in Delphi, which is occasionally crashing with the error message "Control '' has no parent window".

My question is not to understand WHY the error is happening, but to understand why the control has no name assigned.

Is the seeming lack of a name for the control a function of the way the control was coded (i.e., controls can have names but they are optional), or is this because the name of the control is inherited from the (non-existent) parent?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Dan SHEA
  • 29
  • 2
  • 4
    Yes, control names are optional, however controls created at design-time ALWAYS have a name assigned, which is used during DFM streaming. Either the control in question has been created in code at runtime, or the error is happening before the control's Name has been read from the DFM. There is really no way to answer this without seeing the actual code that is failing. – Remy Lebeau Jan 17 '19 at 20:45
  • Like Remy said, it would require the code as well as the dfm to check that out. Moreover it would be a good idea th isolate your problem so you can reproduce it with confidence. Once you goit that, fixing it will probably be pretty easy. – H.Hasenack Jan 17 '19 at 21:02
  • possibly related: https://stackoverflow.com/questions/23316113/control-has-no-parent-window-error – Gabriel Apr 04 '19 at 10:33
  • Possible duplicate of ["Control '' has no parent window" error](https://stackoverflow.com/questions/23316113/control-has-no-parent-window-error) – Gabriel Apr 04 '19 at 10:33

2 Answers2

3

My question is not to understand WHY the error is happening, but to understand why the control has no name assigned.

Controls that are created at runtime, as opposed to design time, need not have names. So, this control has no name because the programmer created it without naming it, or it is a control created internally by another control, without being named.

It is perfectly normal for controls not to be named. It is perfectly reasonable for complex applications never to refer to control names.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Also note there are controls the framework creates at runtime, e.g an inplace edit... – Sertac Akyuz Jan 17 '19 at 21:08
  • 1
    JFTR, even at design time controls are not required to have names. – Uwe Raabe Jan 17 '19 at 22:42
  • 1
    It's also possible that errors that occur during inappropriately premature initialization in the constructor call chain can trigger windowing errors before the streaming system has applied the **Name** property. – Deltics Jan 18 '19 at 02:06
  • Thanks for the responses. My challenge is that I am expected to figure out which application function is throwing this error with no programming knowledge, no access to the source code and logs which don't tell me what the application is doing... only that an unnamed control has no parent. I was hoping that I might be able to respond with 'give your control &^$%#% names', but it appears that it won't be as simple as all that. – Dan SHEA Jan 18 '19 at 14:04
  • I just answered the question that you asked. You made it very clear what your question was, and I quoted that in my answer. – David Heffernan Jan 18 '19 at 14:19
-1

There are multiple reasons, including but not necessarily limited to:

1) It wasn't given a name in the code. 2) It doesn't inherit a name for whatever function called it

Dan SHEA
  • 29
  • 2