Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a component's parent form in Borland VCL?

I'd like to determine which form a given component belongs to in my application. Neither the Parent nor the Owner property can be assumed to be the form itself, so I can't simply use this.

I guess I could just go through the Parent property recursively until I arrive at something derived from TForm, but is there a better way to do this? I used the search function, but couldn't find anything specific to my problem.

I'm using Borland C++ Builder, by the way (tagged Delphi because a majority of VCL users seem to write in Delphi, and I read Delphi code just fine).

Thanks in advance!

like image 658
nklein Avatar asked May 28 '10 11:05

nklein


1 Answers

You could use GetParentForm in Forms unit - it's used by the VCL a lot, too. It does what you mentioned - recursively find the first TCustomForm in its parents. In addition, it also handles design time.

like image 68
Ondrej Kelle Avatar answered Oct 19 '22 23:10

Ondrej Kelle