高分求解决"VCL控件"简单问题
主要想实现的内容:
在TSpeedButton控件基础上增加一个属性btnKind,有(btnCustom, btnPrint, btnPreview)三种属性,当选择btnPrint,btnPreview对应Glyph给出一个默认的图片,这个功能在下面SetbtnKind代码已经实现。
存在问题:现在关键是:假如我选择了btnPrint,出现了一个对应的图片A,但是我认为的利用Glyph属性,重新选择了一个图片B,我希望运行是出现的是图片B而不是A,但是现在出现是图片A,不知什么原因,望给予提示,谢谢!
unit AButton;
interface
uses
SysUtils, Classes, Controls, Buttons, Windows;
type
TbtnKind = (btnCustom, btnPrint, btnPreview);
type
TAButton = class(TSpeedButton)
private
FbtnKind: TbtnKind;
procedure SetbtnKind(const Value: TbtnKind);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property btnKind: TbtnKind read FbtnKind write SetbtnKind default btnCustom;
end;
procedure Register;
implementation
{$R AAAA.res}
{ TAButton }
procedure TAButton.SetbtnKind(const Value: TbtnKind);
begin
if value <> FbtnKind then
begin
NumGlyphs := 2;
if value = btnPreview then
Glyph.LoadFromResourceName(HInstance,'PREVIEW')
else if value = btnPrint then
Glyph.LoadFromResourceName(HInstance,'PRINT');
end;
FbtnKind := Value;
end;
procedure Register;
begin
RegisterComponents('Third', [TAButton]);
end;
end.