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 27 by tony, Tue Apr 14 13:10:23 2015 UTC vs.
Revision 39 by tony, Tue May 17 08:14:52 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 114 | Line 116 | type
116      procedure DoEnter; override;
117      procedure DoExit; override;
118      procedure KeyUp(var Key: Word; Shift: TShiftState); override;
119 +    procedure Loaded; override;
120      procedure Notification(AComponent: TComponent; Operation: TOperation); override;
121      procedure SetItemIndex(const Val: integer); override;
122      function SQLSafe(aText: string): string;
# Line 328 | 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 346 | Line 349 | begin
349                 SelStart := iSelStart;
350                 SelLength := UTF8Length(Text);
351               end;
352 +             KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant;
353             end;
354           end;
355      finally
# Line 364 | Line 368 | begin
368        Parser.Add2WhereClause(GetRelationNameQualifier + '"' + ListField + '" Like ''' +
369                                    SQLSafe(Text) + '%''')
370      else
371 <      Parser.Add2WhereClause(GetRelationNameQualifier + 'Upper("' + ListField + '") Like Upper(''' +
371 >      Parser.Add2WhereClause('Upper(' + GetRelationNameQualifier + '"' +  ListField + '") Like Upper(''' +
372                                    SQLSafe(Text) + '%'')');
373  
374    end;
# Line 379 | Line 383 | end;
383  
384   procedure TIBLookupComboEditBox.HandleEnter(Data: PtrInt);
385   begin
386 +  if AppDestroying in Application.Flags then Exit;
387     SelectAll
388   end;
389  
# Line 392 | 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 456 | Line 467 | end;
467  
468   procedure TIBLookupComboEditBox.DoExit;
469   begin
470 +  if FTimer.Interval <> 0 then
471 +    HandleTimer(nil);
472    FExiting := true;
473    try
474      CheckAndInsert;
# Line 481 | Line 494 | begin
494      SelectAll;
495    end
496    else
497 <  if (IsEditableTextKey(Key) or (Key = VK_BACK))
498 <     and AutoComplete and (Style <> csDropDownList) and
499 <     (not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then
500 <    FTimer.Interval := FKeyPressInterval
501 <  else
502 <    FTimer.Interval := 0
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;
507 > begin
508 >  inherited Loaded;
509 >  IBControlLinkChanged;
510   end;
511  
512   procedure TIBLookupComboEditBox.Notification(AComponent: TComponent;
# Line 544 | 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