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

Comparing ibx/trunk/ibcontrols/IBLookupComboEditBox.pas (file contents):
Revision 26 by tony, Fri Mar 13 10:26:52 2015 UTC vs.
Revision 27 by tony, Tue Apr 14 13:10:23 2015 UTC

# Line 31 | Line 31 | interface
31  
32   uses
33    Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls,
34 <  ExtCtrls, IBSQLParser, DB, StdCtrls;
34 >  ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet;
35  
36   type
37  
# Line 54 | Line 54 | type
54      FOwner: TIBLookupComboEditBox;
55    protected
56      procedure ActiveChanged; override;
57    procedure DataEvent(Event: TDataEvent; Info: Ptrint); override;
57      procedure RecordChanged(Field: TField); override;
58      procedure UpdateData; override;
59    public
60      constructor Create(AOwner: TIBLookupComboEditBox);
61    end;
62  
63 +  { TIBLookupControlLink }
64 +
65 +  TIBLookupControlLink = class(TIBControlLink)
66 +  private
67 +    FOwner: TIBLookupComboEditBox;
68 +  protected
69 +    procedure UpdateSQL(Sender: TObject); override;
70 +  public
71 +    constructor Create(AOwner: TIBLookupComboEditBox);
72 +  end;
73 +
74  
75    { TIBLookupComboEditBox }
76  
# Line 69 | Line 79 | type
79      FCanAutoInsert: TCanAutoInsert;
80      { Private declarations }
81      FDataLink: TIBLookupComboDataLink;
82 +    FIBLookupControlLink: TIBLookupControlLink;
83      FAutoComplete: boolean;
84      FAutoInsert: boolean;
85      FKeyPressInterval: integer;
# Line 87 | Line 98 | type
98      function GetListSource: TDataSource;
99      function GetRelationNameQualifier: string;
100      procedure HandleTimer(Sender: TObject);
101 +    procedure IBControlLinkChanged;
102      procedure ResetParser;
103      procedure RecordChanged(Sender: TObject; aField: TField);
104      procedure SetAutoCompleteText(AValue: TComboBoxAutoCompleteText);
# Line 102 | Line 114 | type
114      procedure DoEnter; override;
115      procedure DoExit; override;
116      procedure KeyUp(var Key: Word; Shift: TShiftState); override;
117 +    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
118      procedure SetItemIndex(const Val: integer); override;
119 +    function SQLSafe(aText: string): string;
120      procedure UpdateShowing; override;
121 +
122    public
123      { Public declarations }
124      constructor Create(TheComponent: TComponent); override;
# Line 118 | Line 133 | type
133      property ItemHeight;
134      property ItemWidth;
135      property ListSource: TDataSource read GetListSource write SetListSource;
136 <    property KeyPressInterval: integer read FKeyPressInterval write FKeyPressInterval default 500;
136 >    property KeyPressInterval: integer read FKeyPressInterval write FKeyPressInterval default 200;
137      property RelationName: string read FRelationName write FRelationName;
138      property OnAutoInsert: TAutoInsert read FOnAutoInsert write FOnAutoInsert;
139      property OnCanAutoInsert: TCanAutoInsert read FOnCanAutoInsert write FOnCanAutoInsert;
# Line 127 | Line 142 | type
142  
143   implementation
144  
145 < uses IBQuery, IBCustomDataSet, LCLType, Variants, LCLProc;
145 > uses IBQuery, LCLType, Variants, LCLProc;
146  
147 < { TIBLookupComboDataLink }
147 > { TIBLookupControlLink }
148  
149 < procedure TIBLookupComboDataLink.ActiveChanged;
149 > constructor TIBLookupControlLink.Create(AOwner: TIBLookupComboEditBox);
150   begin
151 <  FOwner.ActiveChanged(self)
151 >  inherited Create;
152 >  FOwner := AOwner;
153   end;
154  
155 < procedure TIBLookupComboDataLink.DataEvent(Event: TDataEvent; Info: Ptrint);
155 > procedure TIBLookupControlLink.UpdateSQL(Sender: TObject);
156   begin
157 <  {If we are not visible then avoid unnecessary work}
158 <  if not FOwner.Showing then Exit;
157 >  FOwner.UpdateSQL(self,TIBParserDataSet(Sender).Parser)
158 > end;
159  
160 <  if (Event = deCheckBrowseMode) and (Info = 1) and not DataSet.Active then
161 <  begin
162 <    if (DataSet is TIBDataSet) then
163 <      FOwner.UpdateSQL(self,TIBDataSet(DataSet).Parser)
164 <    else
149 <    if (DataSet is TIBQuery) then
150 <      FOwner.UpdateSQL(self,TIBQuery(DataSet).Parser)
151 <  end
152 <  else
153 <    inherited DataEvent(Event, Info);
160 > { TIBLookupComboDataLink }
161 >
162 > procedure TIBLookupComboDataLink.ActiveChanged;
163 > begin
164 >  FOwner.ActiveChanged(self)
165   end;
166  
167   procedure TIBLookupComboDataLink.RecordChanged(Field: TField);
# Line 179 | Line 190 | begin
190    UpdateList
191   end;
192  
193 + procedure TIBLookupComboEditBox.IBControlLinkChanged;
194 + begin
195 +  if (ListSource <> nil) and (ListSource.DataSet <> nil) and (ListSource.DataSet is TIBParserDataSet) then
196 +    FIBLookupControlLink.IBDataSet := TIBCustomDataSet(ListSource.DataSet)
197 +  else
198 +    FIBLookupControlLink.IBDataSet := nil;
199 + end;
200 +
201   function TIBLookupComboEditBox.GetListSource: TDataSource;
202   begin
203    Result := inherited ListSource;
# Line 196 | Line 215 | procedure TIBLookupComboEditBox.ActiveCh
215   begin
216    if not FInserting and not FUpdating then
217       Application.QueueAsyncCall(@DoActiveChanged,0);
218 +  IBControlLinkChanged;
219   end;
220  
221   procedure TIBLookupComboEditBox.DoActiveChanged(Data: PtrInt);
# Line 237 | Line 257 | begin
257   end;
258  
259   procedure TIBLookupComboEditBox.ResetParser;
260 + var curKeyValue: variant;
261   begin
262    if FFiltered then
263    begin
264      FFiltered := false;
265 +    curKeyValue := KeyValue;
266 +    Text := ''; {Ensure full list}
267      UpdateList;
268 +    KeyValue := curKeyValue;
269      UpdateData(self); {Force Scroll}
270    end;
271   end;
# Line 276 | Line 300 | begin
300    begin
301      FDataLink.DataSource := AValue;
302      inherited ListSource := AValue;
303 +    IBControlLinkChanged;
304    end;
305   end;
306  
# Line 336 | Line 361 | begin
361    if FFiltered then
362    begin
363      if cbactSearchCaseSensitive in AutoCompleteText then
364 <      Parser.Add2WhereClause(GetRelationNameQualifier + '"' + ListField + '" Like ''' + Text + '%''')
364 >      Parser.Add2WhereClause(GetRelationNameQualifier + '"' + ListField + '" Like ''' +
365 >                                  SQLSafe(Text) + '%''')
366      else
367 <      Parser.Add2WhereClause(GetRelationNameQualifier + 'Upper("' + ListField + '") Like Upper(''' + Text + '%'')');
367 >      Parser.Add2WhereClause(GetRelationNameQualifier + 'Upper("' + ListField + '") Like Upper(''' +
368 >                                  SQLSafe(Text) + '%'')');
369  
370    end;
371    if cbactSearchAscending in AutoCompleteText then
# Line 352 | Line 379 | end;
379  
380   procedure TIBLookupComboEditBox.HandleEnter(Data: PtrInt);
381   begin
382 <  SelectAll
382 >   SelectAll
383   end;
384  
385   procedure TIBLookupComboEditBox.UpdateLinkData(Sender: TObject);
# Line 462 | Line 489 | begin
489      FTimer.Interval := 0
490   end;
491  
492 + procedure TIBLookupComboEditBox.Notification(AComponent: TComponent;
493 +  Operation: TOperation);
494 + begin
495 +  inherited Notification(AComponent, Operation);
496 +  if (Operation = opRemove) and (AComponent = DataSource) then
497 +    ListSource := nil;
498 + end;
499 +
500   procedure TIBLookupComboEditBox.SetItemIndex(const Val: integer);
501   begin
502    inherited SetItemIndex(Val);
503    FLastKeyValue := KeyValue;
504   end;
505  
506 + function TIBLookupComboEditBox.SQLSafe(aText: string): string;
507 + var I: integer;
508 + begin
509 +  Result := '';
510 +  for I := 1 to length(aText) do
511 +    if aText[I] = '''' then
512 +      Result := Result + ''''''
513 +    else
514 +      Result := Result + aText[I];
515 + end;
516 +
517   procedure TIBLookupComboEditBox.UpdateShowing;
518   begin
519    inherited UpdateShowing;
# Line 479 | Line 525 | constructor TIBLookupComboEditBox.Create
525   begin
526    inherited Create(TheComponent);
527    FDataLink := TIBLookupComboDataLink.Create(self);
528 <  FKeyPressInterval := 500;
528 >  FIBLookupControlLink := TIBLookupControlLink.Create(self);
529 >  FKeyPressInterval := 200;
530    FAutoComplete := true;
531    FTimer := TTimer.Create(nil);
532    FTimer.Interval := 0;
# Line 490 | Line 537 | end;
537   destructor TIBLookupComboEditBox.Destroy;
538   begin
539    if assigned(FDataLink) then FDataLink.Free;
540 +  if assigned(FIBLookupControlLink) then FIBLookupControlLink.Free;
541    if assigned(FTimer) then FTimer.Free;
542    inherited Destroy;
543   end;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines