View Issue Details

IDProjectCategoryView StatusLast Update
0032943LazarusLCLpublic2018-09-23 17:02
ReporterMichal GawryckiAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformwin32OSWindowsOS Version10
Product Version1.9 (SVN)Product Build 
Target Version1.10Fixed in Version1.9 (SVN) 
Summary0032943: TDBLookupComboBox and csDropDown - restore correct ItemIndex
DescriptionIf you enter text that is not in the lookup list and confirm with Enter, text is cleared and ItemIndex is set to -1. Seems that in this case should restore value of ItemIndex to current value of data field.
Applies to TDBlookupComboBox with properties Style=csDropDown and AutoComplete=False
Patch included
Steps To ReproduceStart attached project. Enter any text in DBLookupCombobox that does not appear in lookup list and confirm with Enter. ItemIndex is set to -1 and text is cleared but should display text corresponding to value of data field.
TagsNo tags attached.
Fixed in Revision58898
LazTarget1.10
WidgetsetWin32/Win64
Attached Files
  • dblookupcombo-restitemindex.patch (517 bytes)
    Index: lcl/include/dblookupcombobox.inc
    ===================================================================
    --- lcl/include/dblookupcombobox.inc	(revision 56954)
    +++ lcl/include/dblookupcombobox.inc	(working copy)
    @@ -35,7 +35,13 @@
       if i <> -1 then
         FLookup.UpdateData(i, FScrollListDataset)
       else
    -    Text := '';
    +  begin
    +    i := FLookup.GetKeyIndex;
    +    if i <> -1 then
    +      ItemIndex := i
    +    else
    +      Text := '';
    +  end;
     end;
     
     procedure TDBLookupComboBox.ActiveChange(Sender: TObject);
    
  • test-dblookupcomborest.zip (129,119 bytes)
  • delphi-dblookupcombo.zip (588,729 bytes)

Relationships

related to 0032383 resolvedJesus Reyes TDbComboBox has problems to set data when item changes 
related to 0032463 closedwp Regression - TDBLookupComboBox raise exception 
related to 0029505 resolvedJuha Manninen TCustomDBComboBox does not call FDatalink.Edit 
related to 0033164 resolvedJesus Reyes Start editing in DataSet through DBComboBox, application closes automatically 

Activities

Michal Gawrycki

2018-01-04 19:30

reporter  

dblookupcombo-restitemindex.patch (517 bytes)
Index: lcl/include/dblookupcombobox.inc
===================================================================
--- lcl/include/dblookupcombobox.inc	(revision 56954)
+++ lcl/include/dblookupcombobox.inc	(working copy)
@@ -35,7 +35,13 @@
   if i <> -1 then
     FLookup.UpdateData(i, FScrollListDataset)
   else
-    Text := '';
+  begin
+    i := FLookup.GetKeyIndex;
+    if i <> -1 then
+      ItemIndex := i
+    else
+      Text := '';
+  end;
 end;
 
 procedure TDBLookupComboBox.ActiveChange(Sender: TObject);

Michal Gawrycki

2018-01-04 19:31

reporter  

test-dblookupcomborest.zip (129,119 bytes)

wp

2018-01-07 00:44

developer   ~0105420

Do you know how Delphi is behaving?

Michal Gawrycki

2018-01-08 13:10

reporter   ~0105487

Delphi does not have published "Style" property. It is hard coded to csDropDownList (at least in BDS 2006)

wp

2018-01-08 14:01

developer   ~0105488

Maybe this is the right way to do it. Being able to type in some text in the Lazarus DBLookupCombobox leads to an error situation in which both solutions have the same problem: The user typed some text, but something else will be displayed (the old text in your patch, an empty text in the current version). None of them looks correct to me.

Michal Gawrycki

2018-01-12 17:49

reporter   ~0105709

After a deep look, I see what is wrong.
Delphi TDBLookupComboBox has a different implementation. Both, TDBLookupComboBox and TDBLookupListBox inherit from the same class TDBLookupControl, which inherits from TCustomControl and the content is drawn in the "Paint" method. In Lazarus TDBLookupComboBox inherits from TCustomComboBox, TDBLookupListBox from TCustomListBox. This makes Delphi lookup combo work differently than TComboBox with the Style=csDropDownList. For example, in delphi you can enter text from the keyboard, which will be searched in the lookup list (it looks like a combination of styles csDropDown with AutoComplete and csDropDownList). Lazarus (and probably delphi) combo box with Style=csDropDownList reacts only to the first letter. This is important when entering data from keyboard. So in my opinion, setting Style=csDropDownList permanently is not the best solution.

Michal Gawrycki

2018-01-12 18:13

reporter   ~0105711

I've included delphi example

Michal Gawrycki

2018-01-12 18:13

reporter  

delphi-dblookupcombo.zip (588,729 bytes)

Jesus Reyes

2018-09-07 02:39

developer   ~0110548

Last edited: 2018-09-07 02:41

View 2 revisions

Because we published the style property we have to have some flexibility, for the moment let's restore the old value as Michal propose, if needed later we can add some option for changing the behavior. If the Style is csDropDownList additionally I added code to update the record which is what a delphi user would expect. I applied the patch with a change to reuse existing code, Please test.

Michal Gawrycki

2018-09-23 17:02

reporter   ~0110979

Tested and work correctly. Thanks.

Issue History

Date Modified Username Field Change
2018-01-04 19:30 Michal Gawrycki New Issue
2018-01-04 19:30 Michal Gawrycki File Added: dblookupcombo-restitemindex.patch
2018-01-04 19:31 Michal Gawrycki File Added: test-dblookupcomborest.zip
2018-01-07 00:44 wp Note Added: 0105420
2018-01-08 13:10 Michal Gawrycki Note Added: 0105487
2018-01-08 14:01 wp Note Added: 0105488
2018-01-10 18:45 Juha Manninen Relationship added related to 0032383
2018-01-10 18:46 Juha Manninen Relationship added related to 0032463
2018-01-10 18:46 Juha Manninen Relationship added related to 0029505
2018-01-12 17:49 Michal Gawrycki Note Added: 0105709
2018-01-12 18:13 Michal Gawrycki Note Added: 0105711
2018-01-12 18:13 Michal Gawrycki File Added: delphi-dblookupcombo.zip
2018-09-01 08:00 Jesus Reyes Relationship added related to 0033164
2018-09-06 21:52 Jesus Reyes Assigned To => Jesus Reyes
2018-09-06 21:52 Jesus Reyes Status new => assigned
2018-09-07 02:39 Jesus Reyes Fixed in Revision => 58898
2018-09-07 02:39 Jesus Reyes LazTarget => 1.10
2018-09-07 02:39 Jesus Reyes Note Added: 0110548
2018-09-07 02:39 Jesus Reyes Status assigned => resolved
2018-09-07 02:39 Jesus Reyes Fixed in Version => 1.9 (SVN)
2018-09-07 02:39 Jesus Reyes Resolution open => fixed
2018-09-07 02:39 Jesus Reyes Target Version => 1.10
2018-09-07 02:41 Jesus Reyes Note Edited: 0110548 View Revisions
2018-09-23 17:02 Michal Gawrycki Note Added: 0110979
2018-09-23 17:02 Michal Gawrycki Status resolved => closed