Warum steigst du denn nicht (endlich) auf ne Liste um?
Mit dem Array zur Not halt so (ungetestet). Nach DeleteBlock darf nur ein gültiger Index übergeben werden, sonst knallt's.
Delphi-Quellcode:
TBlock = class
private
FFarbe : TColor;
FPosition : TPoint;
FID : Integer;
function GetX: integer;
function GetY: integer;
procedure SetX(const Value: integer);
procedure SetY(const Value: integer);
public
property X: integer read GetX write SetX;
property Y: integer read GetY write SetY;
property Farbe: TColor read FFarbe write FFarbe;
property Position: TPoint read FPosition write FPosition;
property ID: integer read FID write FID;
procedure Zeichnen;
procedure Assign(const Value: TBlock);
end;
THaupt = class
..
public
procedure DeleteBlock(Index: integer);
procedure Clear;
end;
function TBlock.GetX: integer;
begin
Result := FPosition.X;
end;
function TBlock.GetY: integer;
begin
Result := FPosition.Y;
end;
procedure TBlock.SetX(const Value: integer);
begin
FPosition.X := Value;
end;
procedure TBlock.SetY(const Value: integer);
begin
FPosition.Y := Value;
end;
procedure TBlock.Assign(const Value: TBlock);
begin
FFarbe := Value.Farbe;
FPosition := Value.Position;
FID := Value.ID;
end;
procedure THaupt.DeleteBlock(Index: integer);
var
I, N: integer;
begin
N := Length(Block);
for I := Index to N - 2 do
Block[I].Assign(Block[I + 1]);
Block[N - 1].Free;
SetLength(Block, N - 1);
end;
procedure THaupt.Clear; // in FormDestroy aufrufen
begin
while Length(Block) > 0 do
DeleteBlock(Length(Block) - 1);
end;