Friday, December 26, 2008

Update of StickyButton

In my previous entry I gave code to create a TButton descendant that emulates a TSpeedButton, but can accept 32 bit images from TImageLists (as TButtons do in Delphi 2009, but in contrast to TSpeedButtons). I mentioned that the new component does not automatically change state according to its Action's Checked property (if it is indeed associated with an Action). It turns out that this can be very easily corrected. Just add the following two procedures:

function TdhStickyButton.GetChecked: Boolean;
begin
Result := Down;
end;

procedure TdhStickyButton.SetChecked(Value: Boolean);
begin
Down := Value;
end;

The declaration section now becomes:

type
TdhStickyButton = class(TButton)
private
FDDown: Boolean;
FJustKilledWhenDown: Boolean;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure SetDownState(Value: Boolean);
protected
function GetChecked: Boolean; override;
procedure SetChecked(Value: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
published
property Down: Boolean read FDDown write SetDownState default false;
end;

No comments:

Post a Comment