diff --git a/lcl/include/customcombobox.inc b/lcl/include/customcombobox.inc index d21918731b..98f1fd3de7 100644 --- a/lcl/include/customcombobox.inc +++ b/lcl/include/customcombobox.inc @@ -42,15 +42,17 @@ begin FItems.Free; end; // and use the interface based list - FItems:= NewStrings; + FItems := NewStrings; - TWSCustomComboBoxClass(WidgetSetClass).SetItemIndex(Self, FItemIndex); + if FItemIndex <> -1 then + TWSCustomComboBoxClass(WidgetSetClass).SetItemIndex(Self, FItemIndex); TWSCustomComboBoxClass(WidgetSetClass).SetStyle(Self, FStyle); TWSCustomComboBoxClass(WidgetSetClass).SetArrowKeysTraverseList(Self, FArrowKeysTraverseList); TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly); TWSCustomComboBoxClass(WidgetSetClass).SetMaxLength(Self, FMaxLength); - if FSelStart <> FSelLength then begin + if FSelStart <> FSelLength then + begin ASelStart:= FSelStart; ASelLength:= FSelLength; SelStart:= ASelStart; @@ -898,10 +900,10 @@ end; ------------------------------------------------------------------------------} function TCustomComboBox.GetItemIndex : integer; begin - if not (csDestroying in ComponentState) - and not (csDestroyingHandle in ControlState) and HandleAllocated then + if not (csDestroying in ComponentState) and + not (csDestroyingHandle in ControlState) and HandleAllocated then FItemIndex:= TWSCustomComboBoxClass(WidgetSetClass).GetItemIndex(Self); - Result:=FItemIndex; + Result := FItemIndex; end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/win32/win32listsl.inc b/lcl/interfaces/win32/win32listsl.inc index a5d73a98ea..f736e19ad4 100644 --- a/lcl/interfaces/win32/win32listsl.inc +++ b/lcl/interfaces/win32/win32listsl.inc @@ -375,10 +375,14 @@ begin // restore text in edit box UpdateComboHeight; TWin32WSCustomComboBox.SetText(FSender, EditText); - lItemIndex := IndexOf(EditText); + if EditText = '' then + lItemIndex := -1 + else + lItemIndex := IndexOf(EditText); if lItemIndex <> -1 then TWin32WSCustomComboBox.SetItemIndex(TCustomComboBox(FSender), lItemIndex); - end else + end + else inherited Assign(Source); end; diff --git a/lcl/interfaces/win32/win32wsstdctrls.pp b/lcl/interfaces/win32/win32wsstdctrls.pp index a545ec910d..b7edecc466 100644 --- a/lcl/interfaces/win32/win32wsstdctrls.pp +++ b/lcl/interfaces/win32/win32wsstdctrls.pp @@ -858,12 +858,6 @@ end; class function TWin32WSCustomComboBox.GetItemIndex(const ACustomComboBox: TCustomComboBox): integer; begin Result := SendMessage(ACustomComboBox.Handle, CB_GETCURSEL, 0, 0); - if Result = LB_ERR Then - Begin - Assert(False, 'Trace:[TWin32WidgetSet.IntSendMessage3] Could not retrieve item index '+ - 'via LM_GETITEMINDEX; try selecting an item first'); - Result := -1; - End; end; class function TWin32WSCustomComboBox.GetMaxLength(const ACustomComboBox: TCustomComboBox): integer;