Einzelnen Beitrag anzeigen

Benutzerbild von dizzy
dizzy

Registriert seit: 26. Nov 2003
Ort: Lünen
1.932 Beiträge
 
Delphi 7 Enterprise
 
#1

"array of Pointer" und eine Zugriffsverletzung...

  Alt 4. Feb 2004, 19:42
Hi liebe Leut'!
Ich komme gleich mal zum Punkt...

Folgende Deklaration:

Delphi-Quellcode:
type
  PSolarSystem = ^TSolarSystem;

  TUniverse = class(TObject)
  public
   Width, Height : Int64;
   SolarSystems : array of PSolarSystem;
   SolarSystemCount : integer;
   constructor Create;
   procedure addSolarSystem(Fx, Fy: Int64; planetCount: integer);
  end;

  TEntity = class(TObject);
  TSolarSystem = class(TEntity)
  public
    X, Y : Int64;
    constructor Create;
    procedure init(Fx, Fy: Int64; planetsTotal: integer);
  end;


implementation

constructor TUniverse.Create;
begin
  inherited;
  Width := 10000;
  Height := 10000;
  SetLength(SolarSystems, 10);
  SolarSystemCount := 0;
end;

procedure TUniverse.addSolarSystem(Fx, Fy: Int64; planetCount: integer);
begin
  SolarSystems[SolarSystemCount] := @TSolarSystem.Create;
  SolarSystems[SolarSystemCount].init(Fx, Fy, planetCount);
  inc(SolarSystemCount);
end;


constructor TSolarSystem.Create;
begin
  inherited;
end;

procedure TSolarSystem.init(Fx, Fy: Int64; planetsTotal: integer);
begin
  X := Fx; <----- HIER DIE ZURGIFFSVERLETZUNG !!!
  Y := Fy;
  SetLength(Planets, planetsTotal);
  planetCount := 0;
end;

end.

Und aufgerufen wird so:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var u : TUniverse;
begin
  u := TUniverse.Create;
  u.addSolarSystem(0, 0, 5);
end;

Simple Frage: Warum knallts?

Vielen Dank im Voraus,
dizzy
Fabian K.
INSERT INTO HandVonFreundin SELECT * FROM Himmel
  Mit Zitat antworten Zitat