Autor Beitrag
chaoslion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: Mo 12.12.05 18:35 
Hallo

wie kann ich durch erstellung einer Prozedure
die caption von zb einem label ändern?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure name(str:string);
begin
label1.caption:=str;
end;


erstmal ist es ok wenn nur vom label1 der titel geändert wird.
aber delphi bringt einen fehler:
Undeclared identifier: 'label1'.
jedoch wenn ich zb eine buttonclick prozedur hab geht es,warum dann nicht auch
bei meiner selbsterstellten?

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 12.12.05 20:12 
Moin und :welcome: im Forum!

Weil in dem aktuellen Kontext der Prozedur Label1 nicht bekannt ist. Drei Lösungen:

a) Die Prozedur als Methode der Formularklasse deklarieren (-> deshalb geht das dann bei den ButtonClick-Ereignissen, weil die zur Formularklasse gehören (TForm1.Button...))

b) Du stellst in der Prozedur den Bezug zur Formularklasse her: Form1.Label1.Caption :=...

c) Du gibst der Prozedur das Control einfach mit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure Name(S: String; MyLabel: TLabel);  
begin
  MyLabel.Caption := S;
end;

// Aufruf innerhalb der Formularklasse:
Name('Hallo',Label1);

// Aufruf ausserhalb der Formularklasse:
Name('Hallo',Form1.Label1);


cu
Narses