spktoolbar: Fix memory leak when using actions on buttons in SpkToolbar (issue 0025732). Patch by Jorge Turiel.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3649 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-10-13 18:46:12 +00:00
parent ce54f48dc3
commit ff5dba6c66

View File

@ -48,6 +48,8 @@ type TSpkBaseButton = class;
function IsVisibleLinked: Boolean; override; function IsVisibleLinked: Boolean; override;
end; end;
{ TSpkBaseButton }
TSpkBaseButton = class abstract(TSpkBaseItem) TSpkBaseButton = class abstract(TSpkBaseItem)
private private
FMouseHoverElement : TSpkMouseButtonElement; FMouseHoverElement : TSpkMouseButtonElement;
@ -96,6 +98,7 @@ type TSpkBaseButton = class;
public public
constructor Create(AOwner : TComponent); override; constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure MouseLeave; override; procedure MouseLeave; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
@ -295,6 +298,12 @@ begin
FMouseActiveElement:=beNone; FMouseActiveElement:=beNone;
end; end;
destructor TSpkBaseButton.Destroy;
begin
FreeAndNil(FActionLink);
inherited Destroy;
end;
procedure TSpkBaseButton.Click; procedure TSpkBaseButton.Click;
begin begin
if Assigned(FOnClick) then if Assigned(FOnClick) then
@ -648,14 +657,14 @@ end;
procedure TSpkBaseButton.SetAction(const Value: TBasicAction); procedure TSpkBaseButton.SetAction(const Value: TBasicAction);
begin begin
if Value = nil then if Value = nil then
begin begin
FActionLink.Free; FActionLink.Free;
FActionLink := nil; FActionLink := nil;
end end
else else
begin begin
if FActionLink = nil then if FActionLink = nil then
FActionLink := TSpkButtonActionLink.Create(self); FActionLink := TSpkButtonActionLink.Create(self);
FActionLink.Action := Value; FActionLink.Action := Value;
FActionLink.OnChange := DoActionChange; FActionLink.OnChange := DoActionChange;
ActionChange(Value, csLoading in Value.ComponentState); ActionChange(Value, csLoading in Value.ComponentState);