Autor Beitrag
Arzh-duard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Win XP
D7 Prof
BeitragVerfasst: Fr 28.01.05 13:33 
Hallo,

in meinem Programm erstelle ich ein Label zur Laufzeit. Funktioniert.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var MyLabel: TLabel;
begin
  MyLabel := TLabel.Create(Form1);
  with MyLabel do begin
    Parent := Form1;
    Height := 10;
    Width := 50;
    Caption := 'Label1';
    Left := 50;
    Top := 50;
  end;
end;


Aber wenn ich dieses Label als Array ansteuern will, geht das nicht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  LabelComponent : TComponent;
begin
 LabelComponent := FindComponent('Label1');
 if LabelComponent <> nil then
   TLabel(LabelComponent).Caption := 'Schoenes Wetter';
end;


Wenn ich allerdings vorm Compilieren ein entsprechendes Label platziere und dies dann wie ein Array ansteuere, funktioniert es.
Was muss ich tun, damit das auch bei zur Laufzeit erzeugten Labels geht??

Schon jetzt ein "Danke schön" an diejenigen, die sich darüber den Kopf zerbrechen...

_________________
Meine Programme bestehen aus 90 % Nachforschung und 10 % Programmierarbeit. Ich hoffe das ändert sich eines Tages...
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Fr 28.01.05 13:39 
Arzh-duard hat folgendes geschrieben:
Was muss ich tun, damit das auch bei zur Laufzeit erzeugten Labels geht?

Du musst dein selbsterstelltest Label auch einen Namen geben.

_________________
Ciao, Sprint.
Thunderous
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 25

Win XP, Win 2000, Win 98, FreeBSD, Linux
D5 Prof, FreePascal, Lazarus
BeitragVerfasst: Fr 28.01.05 13:40 
du hast beim Erstellen des Mylabel vergessen, den Namen anzugeben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  with MyLabel do begin
    name:= 'Label1';
    Parent := Form1;
    Height := 10;
    Width := 50;
    Caption := 'Label1';
    Left := 50;
    Top := 50;
  end;
Kedariodakon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 30



BeitragVerfasst: Fr 28.01.05 13:42 
Das "Parent" nicht vergessen...


Bye
Arzh-duard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Win XP
D7 Prof
BeitragVerfasst: Fr 28.01.05 13:47 
Okay Okay Okay,

ich kapier schon! Ich habe das zwar hier aber nicht in meinem Proggy vergessen.
Ich dachte, es sei übersichtlicher, wenn ich nicht den gesamten Quelltext hier reinplatziere. Nun also der vollständige....

Auf 5 verschiedene Panels werden jeweils 10 Labels gelegt.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
for j := 1 to 5 do begin
    PanelComponent := FindComponent('Panel'+IntToStr(j));
    if (PanelComponent <> nil) then begin
      TPanel(PanelComponent).Cursor := crnone;
      for i := 1 to 10 do begin
        myl := TLabel.Create(TPanel(PanelComponent));
        with myl do begin
          name := 'Label'+inttostr(j)+'_'+inttostr(i);
          Parent := TPanel(PanelComponent);
          Height := 34;
          Width := 31;
          Caption := name;
          if i in [1..5] then begin
            Top := 5;
            Left := round(10+(i-1)*(TPanel(PanelComponent).Width/5));
          end else begin
            top := 45;
            Left := round(10+(i-6)*(TPanel(PanelComponent).Width/5));
          end;
          Font.Size := 22;
          Font.Name := 'Arial';
          Font.Style := [fsbold];
          visible := true;
        end;
      end;
    end;
  end;


Die Panel bestehen aber bereits.

_________________
Meine Programme bestehen aus 90 % Nachforschung und 10 % Programmierarbeit. Ich hoffe das ändert sich eines Tages...
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Fr 28.01.05 14:05 
Dann musst du FindComponent von dem Panel und nicht von der Form aufrufen.

_________________
Ciao, Sprint.
Arzh-duard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Win XP
D7 Prof
BeitragVerfasst: Fr 28.01.05 15:12 
Und wie geht das?
Ich rufe das doch bloß so auf:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
for j := 1 to 5 do begin
  PanelComponent := FindComponent('Panel'+IntToStr(j));
    if PanelComponent <> nil then begin
      TPanel(PanelComponent).Visible := true;
      for i := 1 to 10 do begin
        LabelComponent := FindComponent('Label'+inttostr(j)+'_'+inttostr(i));
          if L_Comp <> nil then begin
            
....


Wo kommt denn da dann der Bezug auf Parent vor :?: :?: :?:

_________________
Meine Programme bestehen aus 90 % Nachforschung und 10 % Programmierarbeit. Ich hoffe das ändert sich eines Tages...
Lossy eX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1048
Erhaltene Danke: 4



BeitragVerfasst: Fr 28.01.05 16:23 
Wäre es nicht vielleicht sinnvoller die Labels in einer TList abzulegen? Dann kann man sich das umständliche auf dem Formular rumgesuche sparen und durchsucht dann direkt nur die Label die man selbst erstellt hat!

_________________
Nur die Menschheit ist arrogant genug, um zu glauben sie sei die einzige intelligente Lebensform im All. Wo nicht mal das nachhaltig bewiesen wurde.
Arzh-duard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Win XP
D7 Prof
BeitragVerfasst: Fr 28.01.05 16:26 
Klingt gut, doch wie geht das????

_________________
Meine Programme bestehen aus 90 % Nachforschung und 10 % Programmierarbeit. Ich hoffe das ändert sich eines Tages...
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Fr 28.01.05 17:21 
Arzh-duard hat folgendes geschrieben:
Und wie geht das?

FindComponent ist eine Funktion aus der Klasse TComponent. In deinem Fall rufst du das FindComponent auf, das zu deiner Form gehört. Du musst aber das vom Panel benutzen.
ausblenden Delphi-Quelltext
1:
(PanelComponent as TPanel).FindComponent					

_________________
Ciao, Sprint.
Arzh-duard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Win XP
D7 Prof
BeitragVerfasst: Fr 28.01.05 17:34 
Achso, okay, dann hab ich es kapiert. Vielen Dank!!!

Hab zwar nu ne umständlichere Alternative gewählt aber das umstellen geht ja schnell.

Vielen Dank!

_________________
Meine Programme bestehen aus 90 % Nachforschung und 10 % Programmierarbeit. Ich hoffe das ändert sich eines Tages...