[lazarus] Bug in TToolbar
Mattias Gaertner
nc-gaertnma at netcologne.de
Sun Dec 22 17:50:43 EST 2002
On Sun, 22 Dec 2002 14:50:31 +0100
Martin Smat <martin.smat at tiscali.cz> wrote:
> 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
More information about the Lazarus
mailing list