[lazarus] Bug in TToolbar

Martin Smat martin.smat at tiscali.cz
Sun Dec 22 08:48:19 EST 2002


Hi,
an error in function TToolbar.ButonIndex prevents adding more than one 
toolbar button on the toolbar.

function TToolBar.ButtonIndex(OldIndex, ALeft, ATop: Integer): Integer;
var
   ...
begin
   ...
(1) while (Dist > 0) and (Result < FButtons.Count) do
   begin
     if Result <> OldIndex then
     begin
       Control := TControl(FButtons[Result]);
       if (Control is TToolButton) and TToolButton(Control).Wrap or
         (Result = FButtons.Count - 1) then
       begin
         if Abs(ATop - Control.Top) < Dist then
         begin
           Dist := Abs(ATop - Control.Top);
           Head := Tmp;
           Tail := Result;
         end;
         Tmp := Result + 1;
       end;
     end
     else
       Tail := Result;
     Inc(Result);
   end;
   { Find button on Row closest to ALeft }
(2)  for TempIndex := Head to Tail do
     if (TempIndex <> OldIndex) then
      if FButtons[Result] <> nil then
       if (ALeft <= TControl(FButtons[Result]).Left) then
       Break;
   ...
end;

After ending the While cycle (1), the Result can have a 
value=FButtons.Count. But this is not a valid value in folowing For 
cycle (2).
I suggest to add this line after the While cycle:
   "If Result = FButtons.Count then dec(Result);" or maybe you know some 
better solution.
I wonder this bug doesn't appear in Linux.

Martin Smat.







More information about the Lazarus mailing list