Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Was mache ich falsch? Es wird die falsche Eigenschaft aufgerufen

  Alt 19. Jan 2023, 17:27
Oder vielleicht so?
Delphi-Quellcode:
type
  TTest = class
    strict private
      FBmp: TBitmap;
      FIndex: Integer;
    private
      procedure GenerateBmp;
      function GetSolid: TBitmap;
      function GetTransparent: TBitmap;
    public
      constructor Create;
      destructor Destroy; override;
    public
      property Solid: TBitmap read GetSolid;
      property Transparent: TBitmap read GetTransparent;
      property Index: Integer read FIndex write FIndex;
    end;

implementation

constructor TTest.Create;
begin
  inherited Create;
  FBmp := TBitmap.Create;
  FBmp.Width := 32;
  FBmp.Height := 32;
  FIndex := 0;
end;

destructor TTest.Destroy;
begin
  FBmp.Free;
  inherited Destroy;
end;

procedure TTest.GenerateBmp;
begin
  FBmp.Canvas.TextOut(0, 0, IntToStr(FIndex));
  FBmp.Dormant;
  FBmp.FreeImage;
  Inc(FIndex);
end;

function TTest.GetSolid: TBitmap;
begin
  FBmp.Transparent := False;
  GenerateBmp;
  Result := FBmp;
end;

function TTest.GetTransparent: TBitmap;
begin
  FBmp.Transparent := True;
  GenerateBmp;
  Result := FBmp;
end;
// updated, jaenickes Vorschlag integriert.
Gruß vom KodeZwerg

Geändert von KodeZwerg (19. Jan 2023 um 20:30 Uhr)
  Mit Zitat antworten Zitat