Autor Beitrag
klabri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Fr 07.11.08 19:24 
Hallo

ich habe ein zweidimens. Label-Array (TLabel.Create(Self))erstellt,funktioniert
alles; ich möchte jetzt ein Label anclicken und der
Label-Text soll in einer ListBox erscheinen.
Wo bekomme ich das Click-Ereignis her ..??

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:
procedure TForm30.FormCreate(Sender: TObject);
var
i,j:integer ;
a:array[1..50]of Integer ;
begin
for i:= 0 to 20 do begin
a[i]:=i;
end;
for i:=1 to 10 do
for j:=1 to 10 do
begin
B[i,j]:=TLabel.Create(Self);
With B[i,j] do
begin
Left:=j*30+100;
Top:=i*30+100;
Caption:=IntToStr(a[i]);
Visible:=True;
Parent:=self;
Font.Size:=8;
Font.Style:=Font.Style+[fsBold];
Font.Color:=clBlue;

end;
end;
end;
end.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 07.11.08 19:33 
Hilft das? Mit Listbox kenne ich mich nicht so aus.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.LabelClick(Sender: TObject);
begin
  ShowMessage((Sender as TLabel).Caption);
end;

{..}
for i := 0 to 20 do begin
  for j := 0 to 20 do
    Labels[i, j].OnClick := self.LabelClick;
end;


E: Deine Formatierung ist aber mal ganz schrecklich :shock:. Schonmal etwas von Formatierungstools gehört? Übrigens sollte das With-Statement nicht verwendet werden, das ist "böse" ;).

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:
procedure TForm30.FormCreate(Sender: TObject);
var
  i, j: Integer;
  A: Array[1..50] of Integer;
begin
  for i:= 0 to 20 do
    A[i] := i;
  for i := 1 to 10 do begin
    for j:=1 to 10 do begin
      B[i, j] := TLabel.Create(Self);
      B[i, j].Left := 30 * j + 100;
      B[i, j].Top := 30 * i + 100;
      B[i, j].Caption := IntToStr(A[i]);
      B[i, j].Visible := True;
      //B[i, j].Parent := self;  //unnötig, wird im Create(self) schon gesetzt ;)
      B[i, j].Font.Size := 8;
      B[i, j].Font.Style := B[i, j].Font.Style + [fsBold];
      B[i, j].Font.Color := clBlue;
    end;
  end;
end;

end.


Außerdem solltest du deine Varablen vernünftig benennen! Statt "B" z.B. "Labels".

Das Array "A" verstehe ich nicht. In A[i] steht ja i drin. Und, da es ein lokales Array ist, kannst du überall, wo du A[x] schreibst, auch x schreiben :nut:

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
klabri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Fr 07.11.08 21:25 
Hallo,
hab schon eine Antwort gefunden.Danke für die Hinweise!!