--- ibx/trunk/ibcontrols/IBLookupComboEditBox.pas 2015/07/18 12:30:52 34 +++ ibx/trunk/ibcontrols/IBLookupComboEditBox.pas 2016/01/26 14:38:47 35 @@ -92,6 +92,8 @@ type FUpdating: boolean; FInserting: boolean; FExiting: boolean; + FForceAutoComplete: boolean; + FInCheckAndInsert: boolean; FLastKeyValue: variant; procedure DoActiveChanged(Data: PtrInt); function GetAutoCompleteText: TComboBoxAutoCompleteText; @@ -329,7 +331,7 @@ begin ListSource.DataSet.Active := false; ListSource.DataSet.Active := true; Text := curText; - if not FExiting and Focused and (Text <> '')then + if not FExiting and (FForceAutoComplete or Focused) and (Text <> '')then begin if ListSource.DataSet.Active and (ListSource.DataSet.RecordCount > 0) then begin @@ -395,57 +397,63 @@ procedure TIBLookupComboEditBox.CheckAnd var Accept: boolean; NewKeyValue: variant; begin - if AutoInsert and (Text <> '') and assigned(ListSource) and assigned(ListSource.DataSet) - and ListSource.DataSet.Active and (ListSource.DataSet.RecordCount = 0) then + if FInCheckAndInsert then Exit; + FInCheckAndInsert := true; try - {Is it OK to insert a new list member?} - Accept := true; - if assigned(FOnCanAutoInsert) then - OnCanAutoInsert(self,Text,Accept); - if not Accept then - begin - ResetParser; - Text := FOriginalTextValue; - SelectAll; - Exit; - end; + if AutoInsert and (Text <> '') and assigned(ListSource) and assigned(ListSource.DataSet) + and ListSource.DataSet.Active and (ListSource.DataSet.RecordCount = 0) then + try + {Is it OK to insert a new list member?} + Accept := true; + if assigned(FOnCanAutoInsert) then + OnCanAutoInsert(self,Text,Accept); + if not Accept then + begin + ResetParser; + Text := FOriginalTextValue; + SelectAll; + Exit; + end; - FInserting := true; - try - {New Value} - FFiltered := false; - if assigned(FOnAutoInsert) then - begin - {In an OnAutoInsert handler, the client is expected to insert the new - row into the List DataSet and to set the KeyValue property to the - value of the primary key of the new row.} - OnAutoInsert(self,Text,NewKeyValue); - end - else - begin - ListSource.DataSet.Append; - {The new KeyValue should be determined by an external generator or - in the "OnInsert" handler. If it is the same as the ListField, then - it will be set from the UpdateLinkData method} - try - ListSource.DataSet.Post; - except - ListSource.DataSet.Cancel; - raise; - end; - NewKeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; - end; - Text := ''; {Ensure full list} - UpdateList; - KeyValue := NewKeyValue; - UpdateData(nil); {Force sync with DataField} - finally - FInserting := false - end; - except - Text := FOriginalTextValue; - ResetParser; - raise; + FInserting := true; + try + {New Value} + FFiltered := false; + if assigned(FOnAutoInsert) then + begin + {In an OnAutoInsert handler, the client is expected to insert the new + row into the List DataSet and to set the KeyValue property to the + value of the primary key of the new row.} + OnAutoInsert(self,Text,NewKeyValue); + end + else + begin + ListSource.DataSet.Append; + {The new KeyValue should be determined by an external generator or + in the "OnInsert" handler. If it is the same as the ListField, then + it will be set from the UpdateLinkData method} + try + ListSource.DataSet.Post; + except + ListSource.DataSet.Cancel; + raise; + end; + NewKeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; + end; + Text := ''; {Ensure full list} + UpdateList; + KeyValue := NewKeyValue; + UpdateData(nil); {Force sync with DataField} + finally + FInserting := false + end; + except + Text := FOriginalTextValue; + ResetParser; + raise; + end; + finally + FInCheckAndInsert := false end; end; @@ -486,12 +494,13 @@ begin SelectAll; end else - if (IsEditableTextKey(Key) or (Key = VK_BACK)) - and AutoComplete and (Style <> csDropDownList) and - (not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then - FTimer.Interval := FKeyPressInterval - else + begin FTimer.Interval := 0; + if (IsEditableTextKey(Key) or (Key = VK_BACK)) + and AutoComplete and (Style <> csDropDownList) and + (not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then + FTimer.Interval := FKeyPressInterval; + end; end; procedure TIBLookupComboEditBox.Loaded; @@ -555,6 +564,13 @@ end; procedure TIBLookupComboEditBox.EditingDone; begin + FForceAutoComplete := true; + try + if FTimer.Interval <> 0 then + HandleTimer(nil); + finally + FForceAutoComplete := false; + end; CheckAndInsert; inherited EditingDone; end;