54 |
|
FOwner: TIBLookupComboEditBox; |
55 |
|
protected |
56 |
|
procedure ActiveChanged; override; |
57 |
+ |
procedure DataEvent(Event: TDataEvent; Info: Ptrint); override; |
58 |
|
procedure RecordChanged(Field: TField); override; |
59 |
|
procedure UpdateData; override; |
60 |
|
public |
77 |
|
|
78 |
|
TIBLookupComboEditBox = class(TDBLookupComboBox) |
79 |
|
private |
79 |
– |
FCanAutoInsert: TCanAutoInsert; |
80 |
|
{ Private declarations } |
81 |
|
FDataLink: TIBLookupComboDataLink; |
82 |
|
FIBLookupControlLink: TIBLookupControlLink; |
95 |
|
FForceAutoComplete: boolean; |
96 |
|
FInCheckAndInsert: boolean; |
97 |
|
FLastKeyValue: variant; |
98 |
+ |
FCurText: string; |
99 |
+ |
FModified: boolean; |
100 |
|
procedure DoActiveChanged(Data: PtrInt); |
101 |
|
function GetAutoCompleteText: TComboBoxAutoCompleteText; |
102 |
|
function GetListSource: TDataSource; |
123 |
|
procedure SetItemIndex(const Val: integer); override; |
124 |
|
function SQLSafe(aText: string): string; |
125 |
|
procedure UpdateShowing; override; |
126 |
< |
|
126 |
> |
procedure UpdateData(Sender: TObject); override; |
127 |
|
public |
128 |
|
{ Public declarations } |
129 |
|
constructor Create(TheComponent: TComponent); override; |
147 |
|
|
148 |
|
implementation |
149 |
|
|
150 |
< |
uses IBQuery, LCLType, Variants, LCLProc; |
150 |
> |
uses LCLType, Variants, LCLProc, LazUTF8; |
151 |
|
|
152 |
|
{ TIBLookupControlLink } |
153 |
|
|
169 |
|
FOwner.ActiveChanged(self) |
170 |
|
end; |
171 |
|
|
172 |
+ |
procedure TIBLookupComboDataLink.DataEvent(Event: TDataEvent; Info: Ptrint); |
173 |
+ |
begin |
174 |
+ |
inherited DataEvent(Event, Info); |
175 |
+ |
if Event = deLayoutChange then |
176 |
+ |
FOwner.LookupCache := FOwner.LookupCache; {sneaky way of calling UpdateLookup} |
177 |
+ |
end; |
178 |
+ |
|
179 |
|
procedure TIBLookupComboDataLink.RecordChanged(Field: TField); |
180 |
|
begin |
181 |
|
FOwner.RecordChanged(self,Field); |
195 |
|
{ TIBLookupComboEditBox } |
196 |
|
|
197 |
|
procedure TIBLookupComboEditBox.HandleTimer(Sender: TObject); |
189 |
– |
var ActiveState: boolean; |
198 |
|
begin |
199 |
|
FTimer.Interval := 0; |
200 |
|
FFiltered := Text <> ''; |
323 |
|
var |
324 |
|
iSelStart: Integer; // char position |
325 |
|
sCompleteText, sPrefixText, sResultText: string; |
318 |
– |
curText: string; |
326 |
|
begin |
327 |
|
if assigned(ListSource) and assigned(ListSource.DataSet) and (ListSource.DataSet is TIBCustomDataSet) |
328 |
|
and ListSource.DataSet.Active then |
329 |
|
begin |
330 |
+ |
FCurText := Text; |
331 |
|
FUpdating := true; |
332 |
|
try |
333 |
|
iSelStart := SelStart;//Capture original cursor position |
334 |
|
if ((iSelStart < UTF8Length(Text)) and |
335 |
|
(cbactEndOfLineComplete in AutoCompleteText)) then |
336 |
|
Exit; |
329 |
– |
curText := Text; |
337 |
|
sPrefixText := UTF8Copy(Text, 1, iSelStart); |
338 |
|
ListSource.DataSet.Active := false; |
339 |
|
ListSource.DataSet.Active := true; |
340 |
< |
Text := curText; |
341 |
< |
if not FExiting and (FForceAutoComplete or Focused) and (Text <> '')then |
340 |
> |
Text := FCurText; |
341 |
> |
if not FExiting and (FForceAutoComplete or Focused) and (FCurText <> '')then |
342 |
|
begin |
343 |
|
if ListSource.DataSet.Active and (ListSource.DataSet.RecordCount > 0) then |
344 |
|
begin |
345 |
|
sCompleteText := ListSource.DataSet.FieldByName(ListField).AsString; |
346 |
< |
if (sCompleteText <> Text) then |
346 |
> |
if (sCompleteText <> FCurText) then |
347 |
|
begin |
348 |
|
sResultText := sCompleteText; |
349 |
|
if ((cbactEndOfLineComplete in AutoCompleteText) and |
357 |
|
SelLength := UTF8Length(Text); |
358 |
|
end; |
359 |
|
KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; |
360 |
+ |
end |
361 |
+ |
else |
362 |
+ |
begin |
363 |
+ |
SelStart := iSelStart; |
364 |
+ |
SelLength := 0; |
365 |
|
end; |
366 |
|
end; |
367 |
|
finally |
368 |
|
FUpdating := false |
369 |
|
end; |
370 |
+ |
FModified := true; |
371 |
|
end; |
372 |
|
end; |
373 |
|
|
374 |
|
procedure TIBLookupComboEditBox.UpdateSQL(Sender: TObject; |
375 |
|
Parser: TSelectSQLParser); |
376 |
|
var FieldPosition: integer; |
377 |
+ |
FilterText: string; |
378 |
|
begin |
379 |
|
if FFiltered then |
380 |
|
begin |
381 |
+ |
if FUpdating then |
382 |
+ |
FilterText := FCurText |
383 |
+ |
else |
384 |
+ |
FilterText := Text; |
385 |
|
if cbactSearchCaseSensitive in AutoCompleteText then |
386 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + ListField + '" Like ''' + |
387 |
< |
SQLSafe(Text) + '%''') |
387 |
> |
SQLSafe(FilterText) + '%''') |
388 |
|
else |
389 |
|
Parser.Add2WhereClause('Upper(' + GetRelationNameQualifier + '"' + ListField + '") Like Upper(''' + |
390 |
< |
SQLSafe(Text) + '%'')'); |
390 |
> |
SQLSafe(FilterText) + '%'')'); |
391 |
|
|
392 |
< |
end; |
393 |
< |
if cbactSearchAscending in AutoCompleteText then |
394 |
< |
begin |
395 |
< |
FieldPosition := Parser.GetFieldPosition(ListField); |
378 |
< |
if FieldPosition = 0 then Exit; |
392 |
> |
if cbactSearchAscending in AutoCompleteText then |
393 |
> |
begin |
394 |
> |
FieldPosition := Parser.GetFieldPosition(ListField); |
395 |
> |
if FieldPosition = 0 then Exit; |
396 |
|
|
397 |
< |
Parser.OrderByClause := IntToStr(FieldPosition) + ' ascending'; |
397 |
> |
Parser.OrderByClause := IntToStr(FieldPosition) + ' ascending'; |
398 |
> |
end; |
399 |
|
end; |
400 |
|
end; |
401 |
|
|
559 |
|
ActiveChanged(nil); |
560 |
|
end; |
561 |
|
|
562 |
+ |
procedure TIBLookupComboEditBox.UpdateData(Sender: TObject); |
563 |
+ |
begin |
564 |
+ |
inherited UpdateData(Sender); |
565 |
+ |
FModified := false; |
566 |
+ |
end; |
567 |
+ |
|
568 |
|
constructor TIBLookupComboEditBox.Create(TheComponent: TComponent); |
569 |
|
begin |
570 |
|
inherited Create(TheComponent); |
583 |
|
if assigned(FDataLink) then FDataLink.Free; |
584 |
|
if assigned(FIBLookupControlLink) then FIBLookupControlLink.Free; |
585 |
|
if assigned(FTimer) then FTimer.Free; |
586 |
+ |
Application.RemoveAsyncCalls(self); |
587 |
|
inherited Destroy; |
588 |
|
end; |
589 |
|
|
597 |
|
FForceAutoComplete := false; |
598 |
|
end; |
599 |
|
CheckAndInsert; |
600 |
+ |
if FModified then |
601 |
+ |
Change; {ensure Update} |
602 |
|
inherited EditingDone; |
603 |
|
end; |
604 |
|
|