Autor Beitrag
cux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Do 06.01.05 20:20 
ich habe ein problem:
ich möchte in einer procedure x label kreieren. sie sollen sich dann auf form1 befinden und panel1 untergeordnet sein. sie sollen so benannt werden: label1, label2, label3,... das bekomm ich schon alles nicht hin.
dann wiederum möchte ich in einer schleife auf die labels zugreifen. wie bekommt man das hin, dass man erst mit label1, dann mit label2, usw. arbeitet?
oder kann man sogar ein array mit labels erstellen? also label[1],...

hab von nichts was ich geschrieben habe nen plan, bin also dankbar für jede hilfe!

cux
Stefan S.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 184


D5
BeitragVerfasst: Do 06.01.05 20:26 
Soweit mir bekannt ist kann man mit Delphi keine Arrays von Komponenten machen. Das Problem hatte ich auch schon öfters.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 06.01.05 20:45 
DaSteve hat folgendes geschrieben:
Soweit mir bekannt ist kann man mit Delphi keine Arrays von Komponenten machen. Das Problem hatte ich auch schon öfters.

Hä? Seit wann denn das nicht?
MyBtnArray: array[0..4] of TButton;
geht wunderbar.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 06.01.05 20:54 
Hallo!

Luckie sagte ja schon, dass das geht. Wie es geht, steht in meinem Tutorial zu Arrays, welches hier in der Tutorialsparte oder auf meiner Homepage zu finden ist.

MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Do 06.01.05 21:48 
soweit ich weis, kann man auch mit FindComponent arbeiten... ich guck mal kurz inner hilfe... :D

jap geht:
ausblenden Delphi-Quelltext
1:
(FindComponent('Button1') as TButton).Caption:='asdasdasd';					

damit greife ich auf die Komponente Button1 zu (eigenschaft Name=Button1) und selbstverständlich kann ich den string per schleife verändern. alles klar?
das keyword as sagt nur, dass die komponente ein Button ist, das ist nötig, da sonst z.B. eigenschaften wie Caption nicht ansprechbar sind, da diese nicht auf allen komponenten existieren, (vermute ich...)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 06.01.05 21:50 
Hallo!

Womit Du sie aber noch nicht automatisiert erzeugt hast. Das geht mit einem Array sehr bequem. Und wenn ich cux richtig verstanden habe, soll das ja auch gemacht werden!

MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
cux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Fr 07.01.05 12:22 
und wie kreiert man jetzt labels?
und christian, gib mal nen link zu deinem tutoruial!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 07.01.05 12:43 
Demnächst bitte selber suchen: www.delphi-forum.de/...ntenArrays_7204.html

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Gosa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Fr 07.01.05 18:31 
Eigentlich geht das so:
(Aber irgendwie zeigt der bei mir die Labels nicht an. ABer vielleicht findest du ja raus wodran das liegt. (Nimmt man statt lables z.B Images funktioniert es))

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:
var
  Form1: TForm1;
  vLabels :  array[0..4] of TLabel;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i : byte;
begin
  For i := 0 to 4 do
  Begin
    vLabels[i] := TLabel.Create(nil);
    With vLabels[i] do
    Begin
      parent := Label1.parent;         //Ich glaube hier liegt der Fehler
      autosize := true;
      caption := 'Label' + inttostr(i);
      setbounds(5, 5 + 20 * i, 0, 0);
    End;
  End;
End;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Gosa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Fr 07.01.05 18:57 
Probier mal so. Hab ich eben in Delphi Hilfe gesehen. Aber nicht ausprobiert.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);   
var i : byte;   
begin   
  For i := 0 to 4 do   
  Begin   
    vLabels[i] := TLabel.Create(self);   //<--- statt nil self  
    With vLabels[i] do   
    Begin   
      parent := self;         //<--- statt ... self   
      autosize := true;   
      caption := 'Label' + inttostr(i);   
      setbounds(5, 5 + 20 * i, 0, 0);   
    End;   
  End;   
End;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.