Sign in Join

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

Mailing lists / lazarus / 2011-09

ComboBox bug?

10 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 Hans-Peter Diettrich: During the revision of the StdCtrls documentation I came across an possible bug in…
Show quoted text 7 lines
During the revision of the StdCtrls documentation I came across an possible bug in TCustomComboBox. Whenever the Sorted property is changed (SetSorted), UpdateSorted is called. It looks like UpdateSorted *always* sorts the list, as long as no handle (widget) has been created. This misbehaviour should affect at least the list items in design mode.

What would be the right behavior?

Mattias

Reply by email

Hans-Peter Diettrich

During the revision of the StdCtrls documentation I came across an possible bug in TCustomComboBox.

Whenever the Sorted property is changed (SetSorted), UpdateSorted is called. It looks like UpdateSorted *always* sorts the list, as long as no handle (widget) has been created. This misbehaviour should affect at least the list items in design mode.

Can somebody confirm?

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: When Sorted is False, the items should not be sorted. DoDi
Show quoted text 10 lines
Mattias Gaertner schrieb: >> Whenever the Sorted property is changed (SetSorted), UpdateSorted is >> called. It looks like UpdateSorted *always* sorts the list, as long as >> no handle (widget) has been created. This misbehaviour should affect at >> least the list items in design mode. > > What would be the right behavior? When Sorted is False, the items should not be sorted.
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.

    lIndex := FItems.IndexOf(lText);
    if lIndex >= 0 then
      ItemIndex := lIndex;
  end;
end;

Mattias

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Thu, 22 Sep 2011 19:26:25 +0200 What would be the right behavior? Mattias
Show quoted text 6 lines
> Whenever the Sorted property is changed (SetSorted), UpdateSorted is > called. It looks like UpdateSorted *always* sorts the list, as long as > no handle (widget) has been created. This misbehaviour should affect at > least the list items in design mode. What would be the right behavior?

When Sorted is False, the items should not be sorted.

DoDi

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Thu, 22 Sep 2011 22:48:52 +0200 procedure TCustomComboBox.UpdateSorted; var lText:…
Show quoted text 14 lines
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?

end; end;

I stumbled across more such near-wrong code and comments, not worth bug reports (in customcombobox.inc):

line 55:

   if FSelStart  FSelLength then

Why not: if FSelLength > 0?

line 183:
{------------------------------------------------------------------------------ Method: TCustomComboBox.DoChange
Not followed by DoChange - should be moved, removed or corrected

line 675:

   // ToDo

Looks like Done (in InitializeWnd)

line 737:
{------------------------------------------------------------------------------

   function TCustomComboBox.GetDroppedDown: Boolean;

Should read "SetDroppedDown" - complete or remove

line 1064:
     Result := FReadOnly  false;
Should read: Result := FReadOnly;

Another (general) one:

I found sometimes wrong descriptions for ...Length of strings, mentioning *byte* count instead of count in *logical* UTF-8 chars. How should such descriptions finally read?

1) Should a logical character count be implied, so that only really different (byte/AnsiChar) counts should be mentioned explicitly?

2) Should count in [logical?] [UTF-8?] characters be mentioned wherever applicable? [what about possible future change to Unicode/UTF-16?]

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich

?

Hans-Peter Diettrich hat am 23. September 2011 um 05:40 geschrieben:

Show quoted text 26 lines
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.?
?
?

Show quoted text 11 lines
>? ?end; > end; I stumbled across more such near-wrong code and comments, not worth bug reports (in customcombobox.inc): line 55: ? ? if FSelStart FSelLength then Why not: if FSelLength > 0??

Why not? if (FSelStart>0) or (fSelLength>0)??
?
?

Show quoted text 5 lines
line 183: {------------------------------------------------------------------------------ ? ? Method: TCustomComboBox.DoChange Not followed by DoChange - should be moved, removed or corrected?

fixed ?
?
?

line 675: ? ? // ToDo Looks like Done (in InitializeWnd)?

removed?
?
?

Show quoted text 5 lines
line 737: {------------------------------------------------------------------------------ ? ? function TCustomComboBox.GetDroppedDown: Boolean; Should read "SetDroppedDown" - complete or remove?

removed?
?

line 1064: ? ? ? Result := FReadOnly false; Should read: Result := FReadOnly;?

IMO such things are the programmers choice.
If we would start changing such things we would have to reject many patches. ? ?
?

Show quoted text 13 lines
Another (general) one: I found sometimes wrong descriptions for ...Length of strings, mentioning *byte* count instead of count in *logical* UTF-8 chars. How should such descriptions finally read? 1) Should a logical character count be implied, so that only really different (byte/AnsiChar) counts should be mentioned explicitly? 2) Should count in [logical?] [UTF-8?] characters be mentioned wherever applicable? [what about possible future change to Unicode/UTF-16?]?

I think it should be mentioned wherever applicable. Of course it is enough to add a link to a place where it is explained in detail. ? ??
Mattias
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110923/8797f859/attachment.html>

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner
Show quoted text 33 lines
Hans-Peter Diettrich 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?

Thanks for the fixes :-)

Show quoted text 16 lines
> Another (general) one: > > I found sometimes wrong descriptions for ...Length of strings, > mentioning *byte* count instead of count in *logical* UTF-8 chars. How > should such descriptions finally read? > > 1) Should a logical character count be implied, so that only really > different (byte/AnsiChar) counts should be mentioned explicitly? > > 2) Should count in [logical?] [UTF-8?] characters be mentioned wherever > applicable? [what about possible future change to Unicode/UTF-16?] I think it should be mentioned wherever applicable. Of course it is enough to add a link to a place where it is explained in detail.

I'm using the LCL since many years now, and I never noticed whether the LCL components use Ansi or UTF-8 strings. What's the default, and where is it (or should be) described?

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
Show quoted text 36 lines
Mattias Gaertner schrieb: > Hans-Peter Diettrich 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'm using the LCL since many years now, and I never noticed whether the LCL components use Ansi or UTF-8 strings. What's the default, and where is it (or should be) described?

I guess with 'Ansi' you mean system encoding. Where does the LCL use system encoding?

Mattias

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich: I wonder e.g. why ItemIndex is not tested before all further processing. When nothing has…
Show quoted text 45 lines
Mattias Gaertner schrieb: > On Fri, 23 Sep 2011 16:23:02 +0200 > Hans-Peter Diettrich wrote: > >> Mattias Gaertner schrieb: >>> Hans-Peter Diettrich 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

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Fri, 23 Sep 2011 16:23:02 +0200 What else do you expect to happen? I guess with 'Ansi'…
Show quoted text 40 lines
On Fri, 23 Sep 2011 16:23:02 +0200 Hans-Peter Diettrich wrote: > Mattias Gaertner schrieb: >> Hans-Peter Diettrich 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.

Show quoted text 7 lines
> [...] > I'm using the LCL since many years now, and I never noticed whether the > LCL components use Ansi or UTF-8 strings. What's the default, and where > is it (or should be) described? I guess with 'Ansi' you mean system encoding. Where does the LCL use system encoding?

I'm just asking. I think that I've seen such behaviour somewhere, will watch for concrete occurences.

DoDi

Reply by email