Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

delphi - toolbutton with action created at runtime

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

Kind regards

Christine

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...