![]() |
Form.FindChildControl('ControlName') findet TLabel nicht
Hallo!
Ich habe auf einem Form mehrere Buttons und Labels, deren Caption ich mit folgender Methode ändern:
Delphi-Quellcode:
Ein Aufruf von SetControlCaption('MeinButton', 'Test') ändern nun problemlos die Caption des Buttons "MeinButton" auf "Test". Wenn ich das Gleiche mit einerm Label "MeinLabel" versuche, passiert aber nichts, weil FindChildControl(ControlName) nur nil zurückliefert.
procedure SetControlCaption(ControlName, Caption: String);
begin control := MainForm.FindChildControl(ControlName); if ((control<>nil) and (control is TLabel)) then TLabel(control).Caption := Caption; if ((control<>nil) and (control is TButton)) then TButton(control).Caption := Caption; end; Wenn ich einen Button mit dem Namen "MeinLabel" erstelle, wird dieser prima gefunden und die Caption geändert. Am Namen der Control liegt es also nicht. Warum findet FindChildControl(ControlName) also keine TLabel? Besten Dank Ares |
Re: Form.FindChildControl('ControlName') findet TLabel nicht
Weil FindChildControl nur TWinControl's durchsucht :wink:
Nutze wenn dann FindComponent ... |
Re: Form.FindChildControl('ControlName') findet TLabel nicht
Hallo
In Ergänzung zu Deap-Sea: Es gibt "controls" die sind echte kleine Windowsfensterl'ein mit eigenem WindowHandle und andere welche von delphi selber verwaltet werden. Ein TLabel wird z.b. nur gezeichnet hat aber kein eigenes Windowhandle ... spart ressourcen .... |
Re: Form.FindChildControl('ControlName') findet TLabel nicht
Afaik ist FindComponent auch nicht rekursiv. Das heisst, wenn dein Label z.B. auf einem Panel liegt, wird Form1.FindComponent das ebenfalls nicht finden. In dem Falle brauchst du eine rekursive Funktion, die alle Components auf der Form durchgeht und sich selbst mit dem Control wieder aufruft, wenn ComponentCount eines Controls > 0 ist.
|
Re: Form.FindChildControl('ControlName') findet TLabel nicht
Zitat:
|
Re: Form.FindChildControl('ControlName') findet TLabel nicht
Ah, tatsache ... Wieder was gelernt. :nerd:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz