主要想实现的内容:
  在TSpeedButton控件基础上增加一个属性btnKind,有(btnCustom, btnPrint, btnPreview)三种属性,当选择btnPrint,btnPreview对应Glyph给出一个默认的图片,这个功能在下面SetbtnKind代码已经实现。
存在问题:现在关键是:假如我选择了btnPrint,出现了一个对应的图片A,但是我认为的利用Glyph属性,重新选择了一个图片B,我希望运行是出现的是图片B而不是A,但是现在出现是图片A,不知什么原因,望给予提示,谢谢!
unit AButton;interfaceuses
  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.

解决方案 »

  1.   

    看一下Tspeedbutton源代码,是不是图片刷新有问题。你提供的代码只是在BtnKind属性改变时将图片调出来,按钮刷新时有没有及时改变呢?供参考。
      

  2.   

    图片改变没有问题:
    例如:btnKind
    选择btnPrint 默认出现图片A
    选择btnPreview 默认出现图片B
    假如btnKind我选择btnPrint,默认出现的图片是A,现在我更改这个图片是一个C,
    但是在运行时回自动变为A,且关掉这个控件的Form,下次打开就变为A了。
      

  3.   

    我认识:
    1. property btnKind: TbtnKind read FbtnKind write SetbtnKind default btnCustom;
    这个出了问题. 应该改为: Stored True;
    2. 在TAButton.Create() 析构函数中.好像要加入一个什么属性状态设置. (不好意思.等查一下在上来)
      

  4.   

    是从DFM中读取属性时出的问题。
    你的自定义属性btnKind在Glyph后读取,而你又在btnKind的Set方法中设置了Glyph,所以你事前选定的Glyph当然就无效了。解决的方法是只在设计时设置Glyph。
    或者Glyph在设计时被改动后(当然要区分是你的btnKind属性改的还是用户自己设置的)把btnKind设置成btnCustom之类的不改变Glyph的值。
      

  5.   

    1. property btnKind: TbtnKind read FbtnKind write SetbtnKind default btnCustom;
    ////////////1. property btnKind: TbtnKind read FbtnKind write SetbtnKind ;