Einzelnen Beitrag anzeigen

Benutzerbild von Nonsense
Nonsense

Registriert seit: 23. Nov 2002
389 Beiträge
 
Delphi 5 Standard
 
#12

Re: Wie Array mit Pointern auf Klassen-Instanzen füllen?

  Alt 25. Mär 2004, 16:16
Hier mal meins.

Die Klassen:
Delphi-Quellcode:
  TWorld = class
  private
    FWorldHeight: Integer;
    FWorldWidth: Integer;
    FBufferArray: array of array of TCreature;
    FWorldArray: array of array of TCreature;
  public
    constructor Create(WorldHeight, WorldWidth: Integer);
    destructor Destroy; override;
  end;

  TCreature = class
  private
    FName: string;
  public
  end;

  TGround = class(TCreature)
  private
  public
  end;

  TSand = class(TGround)
  private
  public
    constructor Create;
    destructor Destroy;
  end;
Und hier die Klasse TSand:
Delphi-Quellcode:
constructor TSand.Create;
begin
  inherited Create;

  FName := 'Sand';
end;
Sowie die Klasse TWorld:
Delphi-Quellcode:
constructor TWorld.Create(WorldHeight, WorldWidth: Integer);
var
  i: Integer;
  j: Integer;
  ArrayLength: Integer;
begin
  FWorldHeight := WorldHeight;
  FWorldWidth := WorldWidth;

  ArrayLength := WorldHeight * WorldWidth;
  SetLength(FBufferArray, ArrayLength);
  SetLength(FWorldArray, ArrayLength);

  for i := 0 to FWorldHeight - 1 do
    for j := 0 to FWorldWidth - 1 do
    begin
      FBufferArray[i][j] := TGround.Create;
    end;
end;
  Mit Zitat antworten Zitat