Einzelnen Beitrag anzeigen

Andreas L.

Registriert seit: 23. Mai 2011
Ort: Furth im Wald
308 Beiträge
 
Delphi 11 Alexandria
 
#1

Abgeleitetes TImage - Delphi stürzt ab

  Alt 29. Jun 2011, 15:56
Hallo,
ich habe von TImage eine neue Komponente abgeleitet. Ziehe ich das Objekt zur DesignTime auf die Form, zeigt Delphi die Fehlermeldung

Zitat:
---------------------------
Gefahr
---------------------------
Stapelüberlauf - Speichern Sie Ihre Arbeit und starten Sie CodeGear Delphi für Microsoft Windows erneut
---------------------------
OK
---------------------------
. Nach einem Klick auf OK kann ich noch exakt einen Klick irgendwo in Delphi machen (egal wohin) und die IDE schließt sich automatisch (so schnell hat sich Delphi noch nie geschlossen...)

Wenn ich die Komponente zur RunTime erstelle, kommt zwar keine Meldung, aber das Image wird nicht angezeigt.

So sieht mein Code aus:
Delphi-Quellcode:
unit CsImage;

interface

uses
  SysUtils, Classes, Controls, ExtCtrls, Graphics;

type
  { -------------------------------------------------------------------------- }
  { TCsImage ----------------------------------------------------------------- }
  { -------------------------------------------------------------------------- }
  TCsImage = class(TImage)
  private
    FPicture: TPicture;
    FHoverPicture: TPicture;
    FDisabledPicture: TPicture;
    FOnMouseEnter: TNotifyEvent;
    FOnMouseLeave: TNotifyEvent;
    FDrawHovered: Boolean;
  protected
    procedure SetPicture(Value: TPicture);
    procedure SetHoverPicture(Value: TPicture);
    procedure SetDisabledPicture(Value: TPicture);
    function GetEnabled: Boolean; override;
    procedure SetEnabled(Value: Boolean); override;
    procedure HandleMouseEnter(Sender: TObject);
    procedure HandleMouseLeave(Sender: TObject);
    procedure RefreshPicture;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    property Picture: TPicture read FPicture write SetPicture;
    property DisabledPicture: TPicture read FDisabledPicture write SetDisabledPicture;
    property Enabled: Boolean read GetEnabled write SetEnabled;
    property HoverPicture: TPicture read FHoverPicture write SetHoverPicture;
    property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

implementation

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

  FPicture := TPicture.Create;
  FHoverPicture := TPicture.Create;
  FDisabledPicture := TPicture.Create;

  inherited OnMouseEnter := HandleMouseEnter;
  inherited OnMouseLeave := HandleMouseLeave;
end;

destructor TCsImage.Destroy;
begin
  FreeAndNil(FPicture);
  FreeAndNil(FHoverPicture);
  FreeAndNil(FDisabledPicture);

  inherited Destroy;
end;

procedure TCsImage.Loaded;
begin
  inherited Loaded;

  {if not (csDesigning in ComponentState) then
    SetPicture(FPicture);}

end;

procedure TCsImage.SetPicture(Value: TPicture);
begin
  FPicture.Assign(Value);

  RefreshPicture;
end;

procedure TCsImage.SetHoverPicture(Value: TPicture);
begin
  FHoverPicture.Assign(Value);
end;

function TCsImage.GetEnabled: Boolean;
begin
  Result := inherited Enabled;
end;

procedure TCsImage.SetEnabled(Value: Boolean);
begin
  inherited SetEnabled(Value);

  RefreshPicture;
end;

procedure TCsImage.SetDisabledPicture(Value: TPicture);
begin
  FDisabledPicture.Assign(Value);

  RefreshPicture;
end;

procedure TCsImage.HandleMouseEnter(Sender: TObject);
begin

  FDrawHovered := True;
  RefreshPicture;

  if Assigned(FOnMouseEnter) then
    OnMouseEnter(Sender);
end;

procedure TCsImage.HandleMouseLeave(Sender: TObject);
begin
  FDrawHovered := False;
  RefreshPicture;

  if Assigned(FOnMouseLeave) then
    OnMouseLeave(Sender);
end;

procedure TCsImage.RefreshPicture;
begin

  if (not Enabled) and Assigned(FDisabledPicture) then
    inherited Picture.Assign(FDisabledPicture)
  else if FDrawHovered and Assigned(FHoverPicture) then
    inherited Picture.Assign(FHoverPicture)
  else
    inherited Picture.Assign(FPicture);

end;

end.
Wo könnte das Problem liegen?
Andreas Lauß
Blog
  Mit Zitat antworten Zitat