Thema: Delphi Property (Stackoverload)

Einzelnen Beitrag anzeigen

Benutzerbild von negaH
negaH

Registriert seit: 25. Jun 2003
Ort: Thüringen
2.950 Beiträge
 
#4

Re: Property (Stackoverload)

  Alt 4. Sep 2003, 14:53
So nun mal im Ernst, deine Klassen sind sehr unglücklich deklariert.
Delphi-Quellcode:
type
  TBitmaps = class(TPersistent)
  private
    FBitmaps: array[0..8] of TBitmap;

    function GetBitmap(Index: Integer): TBitmap;
    procedure SetBitmap(Index: Integer; Value: TBitmap);
  protected
  public
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
  published
    property TopLeft: TBitmap index 0 read GetBitmap write SetBitmap;
    property TopMiddle: TBitmap index 1 read GetBitmap write SetBitmap;
    property TopRight: TBitmap index 2 read GetBitmap write SetBitmap;

    property MiddleLeft: TBitmap index 3 read GetBitmap write SetBitmap;
    property MiddleMiddle: TBitmap index 4 read GetBitmap write SetBitmap;
    property MiddleRight: TBitmap index 5 read GetBitmap write SetBitmap;

    property BottomLeft: TBitmap index 6 read GetBitmap write SetBitmap;
    property BottomMiddle: TBitmap index 7 read GetBitmap write SetBitmap;
    property BottomRight: TBitmap index 8 read GetBitmap write SetBitmap;
  end;

implementation

function TBitmaps.GetBitmap(Index: Integer): TBitmap;
begin
  if FBitmaps[Index] = nil then FBitmaps[Index] := TBitmap.Create;
  Result := FBitmaps[Index];
end;

procedure TBitmaps.SetBitmap(Index: Integer; Value: TBitmap);
begin
  GetBitmap(Index).Assign(Value);
end;

procedure TBitmaps.Assign(Source: TPersistent);
var
  I: Integer;
  S: TBitmaps; absolute Source;
begin
  if Source is TBitmaps then
  begin
    for I := Low(FBitmaps) to High(FBitmaps) do
      SetBitmap(I, S.GetBitmap(I));
  end else inherited Assign(Source);
end;

destructor TBitmaps.Destroy;
var
  I: Integer;
begin
  for I := Low(FBitmaps) to High(FBitmaps) do
    FreeAndNil(FBitmaps[I]);
  inherited Destroy;
end;
Allerdings, ich vermute das alle 9 Bitmaps die gleiche Größe + Farbauflösung besitzen. Wenn ja, dann ist eine TImageList mit 9 Bitmaps die absolut bessere Wahl.

Gruß Hagen
  Mit Zitat antworten Zitat