Firemonkey: Getting parent form of control

  

I have a custom control which needs to get access to the height of the main form it is on. Since it is common for this control to be nested in a series of panels, I have written this code to try and get me to the main form:

TControl * control = this;

while( control->HasParent() )
{
control = control->ParentControl;
ShowMessage( control->Name );
}

Using the ShowMessage statement to track my progress, as I step through the code I get all the way up to “BasePanel” which in this case is the last control up the ladder before the “MainForm.” However, when the call to ShowMessage happens for what should be the “MainForm” I get an access violation.

Is there some reason I am unable to access the main form of a control this way? Is there a better way to access a control’s main form?

Comments are closed.