在运行时创建操作的工具按钮 [英] toolbutton with action created at runtime

查看:73
本文介绍了在运行时创建操作的工具按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工具栏中使用 Delphi 2009 Toolbuttons 创建,如下所示:创建 TToolbutton 运行时

I create with Delphi 2009 Toolbuttons in a toolbar like it is desribed here: Create TToolbutton runtime

不同之处在于我也在运行时分配了一个动作.我的代码如下:

The difference is that I assign an action also at runtime. My code is as follows:

Function TSymbolVisWin.MakeButton(BCnt:integer; Act:TAction):integer;
var
TB : TToolButton;
  ACnt, Ind: Integer;
begin
TB:=TToolButton.Create(ListBar);
try
with TB {NB} do
    begin
    Parent:=ListBar;
    Action:=act;  // here seems to be the difference
    Style:=tbsButton;
    grouped:=false;
    Enabled:=true;
    ShowHint:=True;
    Tag:=BCnt;
    Hint:=Act.Hint;
    caption:='';
    Wrap:=False;
    ImageIndex:=Act.ImageIndex;
// here comes the problem
    if ListBar.ButtonCount > 0 then
         Left:=ListBar.Buttons[ListBar.ButtonCount-1].Left+tb.Width
    else
         Left:=0;            }
// end of problem
    end;
except
    end;

当我将行(标记的问题)留在里面时,我看到以下奇怪的行为:

When I leave the lines (marked problem) in, I see followin strange behaviour:

我按下按钮并触发指定的操作,但按钮左侧的两个按钮设置为向下.当我再次按下另一个按钮时,左边两个按钮下降,前一个按钮上升.

I press the button and the assigned action is fired, but the button two buttons left is set to down. when I press an other button again the button two buttons left get down and the button before gets up.

我需要帮助,我不知道原因

I need help, I have no idea for the reason

亲切的问候

克里斯汀

推荐答案

当操作设置了 AutoCheck 时,我可以重复您的问题,如评论中所述.

I can duplicate your problem when actions have AutoCheck set, as mentioned in the comments.

您的错误是没有对问题中链接的问题的公认答案给予足够的关注.答案是在设置 Left 属性之后 将按钮作为父级.在对链接答案的评论中也提到了这一点,这是问题试图解决的问题的原因(尽管那里存在不同的问题 - 可能都与索引混乱有关).

Your mistake is to not to pay enough attention to the accepted answer given to the question linked in your question. The answer have the button parented after setting the Left property. This is also mentioned in the comments to the linked answer to be the cause of the very problem that the question tries to resolve (although a different one there - probably both related with indexes getting messed up).

这篇关于在运行时创建操作的工具按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆