Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Formular eines TWinControls ermitteln (https://www.delphipraxis.net/60579-formular-eines-twincontrols-ermitteln.html)

gmc616 9. Jan 2006 15:28


Formular eines TWinControls ermitteln
 
Irgendwie stehe ich auf dem Schlauch ...

Ich habe (als Beispiel) eine TForm, auf ihr eine Panel, darauf eine Groupbox, dann wieder eine Panel und so weiter uns so weiter.
Ganz oben liegt ein Button.

Nun möchte ich beim Klick auf den Button den Namen des Formular, oder besser das Formular als Objekt direkt, ermitteln.

Die DP-Suche hat mir bisher nicht weiter helfen können ...

marabu 9. Jan 2006 15:38

Re: Formular eines TWinControls ermitteln
 
Hi.

In bestimmten Fällen wirst du weitere Bedingungen einbauen müssen, aber so etwa geht es:

Delphi-Quellcode:
function GetForm(c: TComponent): TForm;
begin
  if c.Owner is TForm
    then Result := c.Owner as TForm
    else Result := GetForm(c.Owner);
end;
Grüße vom marabu

xaromz 9. Jan 2006 15:49

Re: Formular eines TWinControls ermitteln
 
Hallo,

wäre nicht die Suche über Parent angebracht statt über Owner? Ein Owner kann ja irgendeine Komponente sein.

Delphi-Quellcode:
function GetForm(c: TControl): TForm;
begin
  if c.Parent is TForm
    then Result := c.Parent as TForm
    else Result := GetForm(c.Parent);
end;
Gruß
xaromz

marabu 9. Jan 2006 15:55

Re: Formular eines TWinControls ermitteln
 
Recht hast du.

Freundliche Grüße vom marabu

gmc616 9. Jan 2006 15:56

Re: Formular eines TWinControls ermitteln
 
Danke euch Beiden! Beide Funktion funzen Super ...

das Schlüsselwörtchen is war mir entfallen ... :wall:

Wieso lieber parent als owner? Wo ist der Unterschied??

Gruß
gmc

marabu 9. Jan 2006 16:00

Re: Formular eines TWinControls ermitteln
 
xaromz hat Recht - ich stehe manchmal etwas neben mir.

Der Owner ist für das life cycle management zuständig, der Parent für die Visualisierung.

marabu


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:40 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz