Creating Components Manually


Problem I am creating a component at runtime. But when I do this the programm always raises an access violation (EInvalidOperation with message 'Control has no parent window').
Solution If you add any component or control to a form at runtime, you have to set the control's parent immediately after you create the control. Usually the parent of a control is the TWincontrol, that contains it (i.e. the form or a panel control ...).

Delphi:

SomeControl:=TSomeControl.Create(myForm);
SomeCOntrol.Parent:=myForm;

C++ Builder:

TSomeControl* SomeControl = new TSomeControl(myForm);
SomeControl->Parent = myForm;

 


Last Update: 2006-11-21