Hey..jeg har lavet et komponent (mit første) men der sker en fejl når jeg vælger et picture. komponentet er en ImageButton...altså en knap så man assigner 3 billeder. Normal, Hover, Mousedown....men som sagt når jeg assigner et billede kommer der en stack overflow error i delphi og så crasher delphi....hvad er der galt??? her er source
unit ImageButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TOnMouseEvent = procedure( Msg: TWMMouse ) of object;
TImageButton = class(TImage)
private
bNormal: boolean;
bOver: boolean;
bDown: boolean;
bOnMouseEnter: TOnMouseEvent;
bOnMouseLeave: TOnMouseEvent;
bOnMouseDown: TOnMouseEvent;
bOnMouseUp: TOnMouseEvent;
pPic: TPicture;
pPicOver: TPicture;
pPicDown: TPicture;
procedure SetPic(value: TPicture);
procedure SetPicOver(value: TPicture);
procedure SetPicDown(value: TPicture);
protected
procedure WMMouseEnter(var Msg: TWMMouse); message CM_MOUSEENTER;
procedure WMMouseLeave(var Msg: TWMMouse); message CM_MOUSELEAVE;
procedure WMLButtonUp(var Msg: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMLButtonDown(var Msg: TWMLButtonUp); message WM_LBUTTONDOWN;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Picture: TPicture read pPic write SetPic;
property PictureOver: TPicture read pPicOver write SetPicOver;
property PictureDown: TPicture read pPicDown write SetPicDown;
property OnMouseEnter: TOnMouseEvent read bOnMouseEnter write bOnMouseEnter;
property OnMouseLeave: TOnMouseEvent read bOnMouseLeave write bOnMouseLeave;
property OnMouseDown: TOnMouseEvent read bOnMouseDown write bOnMouseDown;
property OnMouseUp: TOnMouseEvent read bOnMouseUp write bOnMouseUp;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Decko', [TImageButton]);
end;
constructor TImageButton.Create;
begin
inherited;
pPic:= TPicture.Create;
pPicOver:= TPicture.Create;
pPicDown:= TPicture.Create;
bNormal:= true;
bOver:= false;
bDown:= false;
end;
destructor TImageButton.Destroy;
begin
pPic.Free;
pPicOver.Free;
pPicDown.Free;
inherited;
end;
procedure TImageButton.WMMouseEnter(var Msg: TWMMouse);
begin
bNormal:= false;
bOver:= true;
bDown:= false;
if bDown then Picture:= pPicDown else Picture:= pPicOver;
if Assigned(bOnMouseEnter) then bOnMouseEnter(Msg);
end;
procedure TImageButton.WMMouseLeave(var Msg: TWMMouse);
begin
bNormal:= true;
bOver:= false;
bDown:= false;
Picture:= pPic;
if Assigned(bOnMouseLeave) then bOnMouseLeave(Msg);
end;
procedure TImageButton.WMLButtonDown(var Msg: TWMMouse);
begin
inherited;
bDown:= true;
if bOver then Picture:= pPicDown;
if Assigned(bOnMouseDown) then bOnMouseDown(Msg);
end;
procedure TImageButton.WMLButtonUp(var Msg: TWMMouse);
begin
inherited;
bNormal:= false;
bOver:= true;
bDown:= false;
if bOver then Picture:= pPicOver;
if Assigned(bOnMouseUp) then bOnMouseUp(Msg);
end;
procedure TImageButton.SetPic(Value: TPicture);
begin
Picture:= Value;
pPic.Assign(Value);
end;
procedure TImageButton.SetPicOver(Value: TPicture);
begin
pPicOver.Assign(Value);
end;
procedure TImageButton.SetPicDown(Value: TPicture);
begin
pPicDown.Assign(Value);
end;
end.
-------------------------------------------------------
Jonas (Decko)
-------------------------------------------------------