Autor Beitrag
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Fr 20.02.09 16:35 
Hallo liebe Community

Ich weiß leider nicht so ganz, warum das nicht funktioniert:
Ich möchte gerne ein Panel anklicken und damit dann ein Child-Control - also ein auf dem Panel postiertes Label (oder später auch ein Image) - sichtbar machen.

Dafür rufe ich beim Anklicken des Panels dann folgende Prozedur auf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure karteAufdecken(aufzudeckendesPanel: TPanel);
var aufzudeckendesLabel:tlabel;
begin
aufzudeckendesLabel:=TLabel(aufzudeckendesPanel.FindChildControl('Label%'));
if aufzudeckendesLabel<>nil then
        aufzudeckendesLabel.Visible:=true
end;

Das funktioniert aber so leider nicht!
Gilt das Label nicht gleich beim Positionieren auf einem Panel als dessen ChildControl?
Wie bekomme ich das denn hin? Muss ich dafür extra erst eine eigene Klasse erstellen?

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Do 26.02.2009 um 22:51
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 20.02.09 16:38 
Was soll Label% sein? Bist du sicher, dass der Name stimmt, der da in Wirklichkeit (also im realen Quelltext) steht?
ffgorcky Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Fr 20.02.09 17:35 
Soweit ich das verstanden habe, kann das Zeichen % doch für eine beliebige Nummer stehen - oder?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 20.02.09 17:47 
Das Zeichen % ist das Zeichen %, sonst nix. ;-)
(Rein hypothetisch: Wenn das funktionieren würde, bekommst du ja auch nur einen Rückgabewert, was wenn mehrere passende da wären?)
Du musst da schon exakt den richtigen Namen angeben.

Wenn du alle Komponenten im Panel durchgehen willst und nicht eine bestimmte Komponente ansprechen willst, dann musst du das Array aufzudeckendesPanel.Components durchgehen.
ffgorcky Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: So 22.02.09 12:40 
Ja - kann mir denn dan mal einer sagen, welches Zeichen dann eine beliebige Zahl darstellt? Oder wie soll ich das ChildControl denn sonst finden?
- Oder kann ich immer einfach das erste ChildControl in einer Liste ansprechen (weil bei mir ja auch immer nur ein Control auf dem Panel ist)?

Oder erst mal noch ganz anders:
Ist denn eine auf dem Panel platzierte Komponente schon ein Child-Control?
- Oder muss ich dafür erst mal eine eigene Komponente entwerfen? - Wenn ja, wie geht das??? (Ein konkreter Link wäre dazu recht hilfreich)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 22.02.09 12:56 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  i: Integer;
  CurPanel: TPanel;
begin
  if not (Sender is TPanel) then
    Exit
  else
    CurPanel := TPanel(Sender);
  for i := 0 to CurPanel.ControlCount - 1 do
    if CurPanel.Controls[i] is TLabel then
      TLabel(CurPanel.Controls[i]).Visible := True

    // und sowas ginge auch:
    else
      ShowMessage(CurPanel.Controls[i].Name);
ffgorcky Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Do 26.02.09 21:46 
Ja - Danke! Das klappt!
Ich dachte mir doch, das das eigentlich recht einfach sein müsste!