ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/ibcontrols/IBLookupComboEditBox.pas
(Generate patch)

Comparing ibx/trunk/ibcontrols/IBLookupComboEditBox.pas (file contents):
Revision 34 by tony, Tue Jul 14 15:31:25 2015 UTC vs.
Revision 35 by tony, Tue Jan 26 14:38:47 2016 UTC

# Line 92 | Line 92 | type
92      FUpdating: boolean;
93      FInserting: boolean;
94      FExiting: boolean;
95 +    FForceAutoComplete: boolean;
96 +    FInCheckAndInsert: boolean;
97      FLastKeyValue: variant;
98      procedure DoActiveChanged(Data: PtrInt);
99      function GetAutoCompleteText: TComboBoxAutoCompleteText;
# Line 329 | Line 331 | begin
331           ListSource.DataSet.Active := false;
332           ListSource.DataSet.Active :=  true;
333           Text := curText;
334 <         if not FExiting and Focused and (Text <> '')then
334 >         if not FExiting and (FForceAutoComplete or Focused) and (Text <> '')then
335           begin
336             if ListSource.DataSet.Active and (ListSource.DataSet.RecordCount > 0) then
337             begin
# Line 395 | Line 397 | procedure TIBLookupComboEditBox.CheckAnd
397   var Accept: boolean;
398      NewKeyValue: variant;
399   begin
400 <  if AutoInsert and (Text <> '') and assigned(ListSource) and assigned(ListSource.DataSet)
401 <     and ListSource.DataSet.Active and (ListSource.DataSet.RecordCount = 0) then
400 >  if FInCheckAndInsert then Exit;
401 >  FInCheckAndInsert := true;
402    try
403 <    {Is it OK to insert a new list member?}
404 <    Accept := true;
405 <    if assigned(FOnCanAutoInsert) then
406 <       OnCanAutoInsert(self,Text,Accept);
407 <    if not Accept then
408 <    begin
409 <      ResetParser;
410 <      Text := FOriginalTextValue;
411 <      SelectAll;
412 <      Exit;
413 <    end;
403 >       if AutoInsert and (Text <> '') and assigned(ListSource) and assigned(ListSource.DataSet)
404 >          and ListSource.DataSet.Active and (ListSource.DataSet.RecordCount = 0) then
405 >       try
406 >         {Is it OK to insert a new list member?}
407 >         Accept := true;
408 >         if assigned(FOnCanAutoInsert) then
409 >            OnCanAutoInsert(self,Text,Accept);
410 >         if not Accept then
411 >         begin
412 >           ResetParser;
413 >           Text := FOriginalTextValue;
414 >           SelectAll;
415 >           Exit;
416 >         end;
417  
418 <    FInserting := true;
419 <    try
420 <      {New Value}
421 <      FFiltered := false;
422 <      if assigned(FOnAutoInsert) then
423 <      begin
424 <        {In an OnAutoInsert handler, the client is expected to insert the new
425 <         row into the List DataSet and to set the KeyValue property to the
426 <         value of the primary key of the new row.}
427 <        OnAutoInsert(self,Text,NewKeyValue);
428 <      end
429 <      else
430 <      begin
431 <        ListSource.DataSet.Append;
432 <        {The new KeyValue should be determined by an external generator or
433 <         in the "OnInsert" handler. If it is the same as the ListField, then
434 <         it will be set from the UpdateLinkData method}
435 <        try
436 <          ListSource.DataSet.Post;
437 <        except
438 <          ListSource.DataSet.Cancel;
439 <          raise;
440 <        end;
441 <        NewKeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant;
442 <      end;
443 <      Text := ''; {Ensure full list}
444 <      UpdateList;
445 <      KeyValue := NewKeyValue;
446 <      UpdateData(nil); {Force sync with DataField}
447 <    finally
448 <      FInserting := false
449 <    end;
450 <  except
451 <    Text := FOriginalTextValue;
452 <    ResetParser;
453 <    raise;
418 >         FInserting := true;
419 >         try
420 >           {New Value}
421 >           FFiltered := false;
422 >           if assigned(FOnAutoInsert) then
423 >           begin
424 >             {In an OnAutoInsert handler, the client is expected to insert the new
425 >              row into the List DataSet and to set the KeyValue property to the
426 >              value of the primary key of the new row.}
427 >             OnAutoInsert(self,Text,NewKeyValue);
428 >           end
429 >           else
430 >           begin
431 >             ListSource.DataSet.Append;
432 >             {The new KeyValue should be determined by an external generator or
433 >              in the "OnInsert" handler. If it is the same as the ListField, then
434 >              it will be set from the UpdateLinkData method}
435 >             try
436 >               ListSource.DataSet.Post;
437 >             except
438 >               ListSource.DataSet.Cancel;
439 >               raise;
440 >             end;
441 >             NewKeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant;
442 >           end;
443 >           Text := ''; {Ensure full list}
444 >           UpdateList;
445 >           KeyValue := NewKeyValue;
446 >           UpdateData(nil); {Force sync with DataField}
447 >         finally
448 >           FInserting := false
449 >         end;
450 >       except
451 >         Text := FOriginalTextValue;
452 >         ResetParser;
453 >         raise;
454 >       end;
455 >  finally
456 >    FInCheckAndInsert := false
457    end;
458   end;
459  
# Line 486 | Line 494 | begin
494      SelectAll;
495    end
496    else
497 <  if (IsEditableTextKey(Key) or (Key = VK_BACK))
490 <     and AutoComplete and (Style <> csDropDownList) and
491 <     (not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then
492 <    FTimer.Interval := FKeyPressInterval
493 <  else
497 >  begin
498      FTimer.Interval := 0;
499 +    if (IsEditableTextKey(Key) or (Key = VK_BACK))
500 +       and AutoComplete and (Style <> csDropDownList) and
501 +       (not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then
502 +      FTimer.Interval := FKeyPressInterval;
503 +  end;
504   end;
505  
506   procedure TIBLookupComboEditBox.Loaded;
# Line 555 | Line 564 | end;
564  
565   procedure TIBLookupComboEditBox.EditingDone;
566   begin
567 +  FForceAutoComplete := true;
568 +  try
569 +  if FTimer.Interval <> 0 then
570 +    HandleTimer(nil);
571 +  finally
572 +    FForceAutoComplete := false;
573 +  end;
574    CheckAndInsert;
575    inherited EditingDone;
576   end;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines