Marco Cantu 78 Posted November 20, 2018 See my latest blog post at http://blog.marcocantu.com/blog/2018-nov-vcl-permonitorv2_getsystemmetrics.html 3 Share this post Link to post
Kryvich 165 Posted November 20, 2018 (edited) Quote This is compatible in terms of parameters with the Windows API of the same name, so an existing call to the API in one of your components gets redirected to the method, which in turn calls GetSystemMetricsForWindow passing the control's parent handle as parameter. If I understand properly, to get a form's handle that a component belongs to, you need to use its Owner property, not the Parent property. type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin if Button1.Parent.Handle = Panel1.Handle then ShowMessage('My parent is Panel1'); if (Button1.Owner as TWinControl).Handle = Form1.Handle then ShowMessage('My owner is Form1'); end; Good addition BTW! Edited November 20, 2018 by Kryvich Share this post Link to post
Uwe Raabe 2057 Posted November 20, 2018 The Owner is not necessarily the form. Sometimes the owner is a TFrame descendant or may even be nil. Iterating the Parent until a TCustomForm is found is usually the way to get the required form instance. Perhaps iterating until Parent is nil is another valid approach. That would also cover the case where one form is parented into another one. 5 Share this post Link to post
Marco Cantu 78 Posted November 21, 2018 On 11/20/2018 at 11:49 AM, Kryvich said: If I understand properly, to get a form's handle that a component belongs to, you need to use its Owner property, not the Parent property. Actually I was imprecise. It doesn't use the parent handle, but walks over the parent hierarchy up to the containing form 1 Share this post Link to post
Remy Lebeau 1393 Posted February 8, 2019 On 11/20/2018 at 3:36 AM, Uwe Raabe said: Iterating the Parent until a TCustomForm is found is usually the way to get the required form instance. Perhaps iterating until Parent is nil is another valid approach. That would also cover the case where one form is parented into another one. The VCL has a GetParentForm() function in the Vcl.Forms unit for this very purpose. Share this post Link to post