On Fri, 23 Sep 2011 22:24:15 +0200 Hans-Peter Diettrich <drdiettri...@aol.com> wrote:
> Mattias Gaertner schrieb: > > On Fri, 23 Sep 2011 16:23:02 +0200 > > Hans-Peter Diettrich <drdiettri...@aol.com> wrote: > > > >> Mattias Gaertner schrieb: > >>> Hans-Peter Diettrich <drdiettri...@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 -- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus