views:

191

answers:

2

Hi,

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!

+13  A: 

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.

TOndrej
A: 

I didn't know that function, but it works fine. Thanks a lot!

nklein
I realize you are new and have even created multiple accounts. But you should not use answers for feedback on answers. Either comment on the answer - for which you don't have enough reputation yet - or just upvote and accept the answer. But for that you need to have an account you are returning to. Ask some moderator to merge your accounts. Use the email address in the footer (contact us) as long as you don't have enough rep to flag for mod attention.
Ralph Rickenbach