Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...