Показать сообщение отдельно
  #3  
Старый 03.06.2010, 04:42
Kapitoshka438 Kapitoshka438 вне форума
Начинающий
 
Регистрация: 09.11.2009
Сообщения: 145
Репутация: 238
По умолчанию

Можно еще вот так.
Код:
unit Unit2;

interface

type
  TPoint = class
  end;

  TVector3i = class(TPoint)
    X1, X2, X3: Integer;
  end;

  TVector4i = class(TPoint)
    X1, X2, X3, X4: Integer;
  end;

  TSingle = class(TPoint)
    X1: Single;
  end;

  TPointClass = class of TPoint;

  TBaseLocations = class
    FClassIndex: Integer;
    Location : array of Integer;
    Name: array of ^string;
    Value: array of TPoint;
    procedure SetLengthFor(NewLength: Integer);
    destructor Destroy; override;
  end;

  TInteger3Locations = class(TBaseLocations)
    constructor Create;
  end;

  TInteger4Locations = class(TBaseLocations)
    constructor Create;
  end;

  TFloat1fLocations = class(TBaseLocations)
    constructor Create;
  end;

var
  PointsClasses: array [1..3] of TPointClass = (TVector4i, TVector3i, TSingle);

implementation

{ TBaseLocations }

destructor TBaseLocations.Destroy;
var
  I: Integer;
begin
  for I := Low(Value) to High(Value) do
    Value[i].Free;
  inherited;
end;

procedure TBaseLocations.SetLengthFor(NewLength: Integer);
var
  I: Integer;
begin
  SetLength(Location, NewLength);
  SetLength(Name, NewLength);
  SetLength(Value, NewLength);
  for I := 0 to NewLength - 1 do begin
    Value[i] := PointsClasses[i].Create;
    New(Name[i]);
  end;
end;

{ TInteger3Locations }

constructor TInteger3Locations.Create;
begin
  FClassIndex := 2;
end;

{ TInteger4Locations }

constructor TInteger4Locations.Create;
begin
  FClassIndex := 1;
end;

{ TFloat1fLocations }

constructor TFloat1fLocations.Create;
begin
  FClassIndex := 3;
end;

end.
Ответить с цитированием