Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2002-12

Bug in TToolbar

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner
to Martin Smat: an error in function TToolbar.ButonIndex prevents adding more than one toolbar button on…
Show quoted text 44 lines
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);"

Applied

or maybe you know some better solution. I wonder this bug doesn't appear in Linux.

All developers agree, the toolbar code should be rewritten.

Mattias

Reply by email

Martin Smat

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.

Reply by email