[Lazarus] ComboBox bug?
Mattias Gaertner
nc-gaertnma at netcologne.de
Fri Sep 23 21:53:53 CEST 2011
On Fri, 23 Sep 2011 22:24:15 +0200
Hans-Peter Diettrich <DrDiettrich1 at aol.com> wrote:
> Mattias Gaertner schrieb:
> > On Fri, 23 Sep 2011 16:23:02 +0200
> > Hans-Peter Diettrich <DrDiettrich1 at aol.com> wrote:
> >
> >> Mattias Gaertner schrieb:
> >>> Hans-Peter Diettrich <DrDiettrich1 at aol.com> hat am 23. September 2011 um
> >>> 05:40 geschrieben:
> >>>
> >>> > Mattias Gaertner schrieb:
> >>> >
> >>> > > procedure TCustomComboBox.UpdateSorted;
> >>> > > var
> >>> > > lText: string;
> >>> > > lIndex: integer;
> >>> > > begin
> >>> > > if HandleAllocated then
> >>> > > TWSCustomComboBoxClass(WidgetSetClass).Sort(Self, Items, FSorted)
> >>> > > else if FItems is TStringList then
> >>> > > begin
> >>> > > // remember text
> >>> > > lText := Text;
> >>> > > TStringList(FItems).Sorted := FSorted;
> >>> > >
> >>> > > When not FSorted then items are not sorted.
> >>> >
> >>> > You're right.
> >>> >
> >>> > But the following then is also evitable (but does no harm):
> >>> >
> >>> > > lIndex := FItems.IndexOf(lText);
> >>> > > if lIndex >= 0 then
> >>> > > ItemIndex := lIndex;
> >>> >
> >>> > What if lIndex=-1?
> >>>
> >>>
> >>>
> >>> Nothing.
> >> Obviously - but why?
> >
> > What else do you expect to happen?
>
> I wonder e.g. why ItemIndex is not tested before all further processing.
> When nothing has been selected before sorting, then after sorting
> nothing should be/become selected as well.
ItemIndex -1 means the text does not exist in the list.
Mattias
More information about the Lazarus
mailing list