Einzelnen Beitrag anzeigen

Benutzerbild von NoGAD
NoGAD

Registriert seit: 31. Jan 2006
Ort: Weimar
345 Beiträge
 
Delphi 10.4 Sydney
 
#28

AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt

  Alt 17. Mai 2024, 09:16
Guten Morgen.

Hier ist ein Test, damit ich das Prinzip verstehen kann.

Was mir jetzt fehlt, sind folgende Properties:
Falls möglich, hätte ich die gerne gebündelt dargestellt, will heißen, im ObjectExplorer sollte z.B.:

Code:
aImage + (aufklappbar)
  - Caption
  - Visible
aImage + (aufklappbar)
  - Picture
  - Visible
[..] (weitere property)
erreichbar sein.

Code:
TMyLabel ->
    property Caption;
    property Visible; // als Test

TMyImage ->
    property Picture;
    property Visible; // auch ein Test
Delphi-Quellcode:
unit ImageLabelTEST;

interface

uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Graphics, Vcl.Forms;

type
  TMyImage = class(TImage)
  private
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Picture;
    property Visible;
  end;

  TMyLabel = class(TLabel)
  private
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Caption;
    property Visible;
  end;

  TImageLabelTEST = class(TCustomControl)
  private
    FImage: TMyImage;
    FLabel: TMyLabel;

    function GetImage: TPicture;
    procedure SetImage(const Value: TPicture);

    function GetLabelCaption: TCaption;
    procedure SetLabelCaption(const Value: TCaption);
    function GetLabelFont: TFont;
    procedure SetLabelFont(const Value: TFont);
  protected
    procedure Resize; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property aImage: TMyImage read FImage;
    property aLabel: TMyLabel read FLabel;
  published
// folgende properties würde ich gerne mit den properties aus den eigenen Subkomponenten ersetzen
    property I_Picture: TPicture read GetImage write SetImage;

    property L_Caption: TCaption read GetLabelCaption write SetLabelCaption;
    property L_Font: TFont read GetLabelFont write SetLabelFont;

    property Align;
    property Anchors;
    property Visible;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('TRM', [TImageLabelTEST]);
end;

{ TMyImage }
constructor TMyImage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

end;

destructor TMyImage.Destroy;
begin
  Self.Free;
  inherited Destroy;

end;

{ TMyLabel }
constructor TMyLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

end;

destructor TMyLabel.Destroy;
begin
  Self.Free;
  inherited Destroy;

end;

{ TImageLabel }
constructor TImageLabelTEST.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FImage := TMyImage.Create(Self);
  FImage.Parent := Self;
  FImage.Align := alTop;
  FImage.Height := 100;

  FLabel := TMyLabel.Create(Self);
  FLabel.Parent := Self;
  FLabel.Align := alClient;
  FLabel.Alignment := taCenter;
end;

procedure TImageLabelTEST.Resize;
begin
  inherited;

end;

function TImageLabelTEST.GetImage: TPicture;
begin
  Result := FImage.Picture;

end;

procedure TImageLabelTEST.SetImage(const Value: TPicture);
begin
  FImage.Picture.Assign(Value);

end;

function TImageLabelTEST.GetLabelCaption: TCaption;
begin
  Result := FLabel.Caption;

end;

procedure TImageLabelTEST.SetLabelCaption(const Value: TCaption);
begin
  FLabel.Caption := Value;

end;

function TImageLabelTEST.GetLabelFont: TFont;
begin
  Result := FLabel.Font;

end;

procedure TImageLabelTEST.SetLabelFont(const Value: TFont);
begin
  FLabel.Font.Assign(Value);

end;

destructor TImageLabelTEST.Destroy;
begin
  FImage.Free;
  FLabel.Free;
  inherited Destroy;

end;

end.
Mathias
Ich vergesse einfach zu viel.
  Mit Zitat antworten Zitat