Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Feld (Array) von Shapes (https://www.delphipraxis.net/114710-feld-array-von-shapes.html)

tra 30. Mai 2008 00:18


Feld (Array) von Shapes
 
Liebe Delphi-Profis,

mein Problem ist Folgendes:

Ich möchte gerne auf einem Formular mit ca. 10 gleichatigen Shapes (z.B. Kugeln) arbeiten.
Erzeuge ich Shape für Shape, "nummeriert" Delphi diese mit Shape1, Shape2, ... Shape10 durch.
Jetzt kann ich aber diese Shapes nicht gleichartig ansprechen.
Es wäre mir lieber, die Namen hießen Shape[1], Shape[2], ..., Shape[10] - ein Array eben. Dann könnte ich jedes einzelne Shape gleichartig z.B. mit einer FOR-Schleife durch Shape[i] ansprechen.

Weiß von euch jemand, wie man ein Array von Shapes erzeugt?

Viele Grüße

mkinzler 30. Mai 2008 06:36

Re: Feld (Array) von Shapes
 
Delphi-Quellcode:
shapes: Array of Shapes;
i: integer;
...
for i := 0 to Anzahl - 1
    shapes[i] := TShape.Create( <Owner>);
    shapes[i].Parent := <Parent>;
    shapes[i].Left := ...

marabu 30. Mai 2008 07:04

Re: Feld (Array) von Shapes
 
Herzlich willkommen in der Delphi-PRAXiS, tra.

Hier nur ein paar subtile Änderungen an den Code-Zeilen von Markus:

Delphi-Quellcode:
type
  TDemoForm = class(TForm)
  // ...
  private
    shapes: array of TShape;
    procedure CreateShapes(n: Word; wc: TWinControl);
  end;

procedure TDemoForm.CreateShapes(n: Word; wc: TWinControl);
begin
  SetLength(shapes, n);
  while n > 0 do
  begin
    Dec(n);
    shapes[n] := TShape.Create(self);
    shapes[n].Parent := wc;
    // ...
  end;
end;
Freundliche Grüße


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:43 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz