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 TLabel.create parent probleme (https://www.delphipraxis.net/75991-tlabel-create-parent-probleme.html)

day 28. Aug 2006 12:40


TLabel.create parent probleme
 
hallo
Ich möchte gerne eine label dynamisch generieren. Das ParentConrol muss ja von Type TWinControl sein. Wie komme ich da ran?
lFrom ist vom Type TForm und darauf befindet sich ein Panel auf welchem ich ein Label positionieren möchte.

Delphi-Quellcode:

           lComponent := lForm.FindComponent('Panel');

           lValueLabel := TLabel.Create(lComponent);
           lValueLabel.Parent := lComponent; //->> funktioniert so nicht, da lComponent vom Type TComponent ist.

mkinzler 28. Aug 2006 12:45

Re: TLabel.create parent probleme
 
Zitat:

Das ParentConrol muss ja von Type TWinControl sein
Komponente sollte reichen.

Christian Seehase 28. Aug 2006 12:47

Re: TLabel.create parent probleme
 
Moin day,

dazu musst Du nur einen TypeCast durchführen.
Sollte so funktionieren:

Delphi-Quellcode:
lValueLabel.Parent := lComponent as TWinControl;

Peter81 28. Aug 2006 12:47

Re: TLabel.create parent probleme
 
Hallo,

du musst nur kontrollieren ob die Komponente vom Typ TWinControl ist und dann nach diesem Typ casten!

Delphi-Quellcode:
lComponent := lForm.FindComponent('Panel');
lValueLabel := TLabel.Create(lComponent);
if lComponent is TWinControl then
  lValueLabel.Parent := TWinControl(lComponent);

day 28. Aug 2006 16:24

Re: TLabel.create parent probleme
 
danke hat funkioniert


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:28 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