31 |
|
|
32 |
|
uses |
33 |
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls, |
34 |
< |
ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet; |
34 |
> |
ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet, LCLVersion; |
35 |
|
|
36 |
|
type |
37 |
|
|
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 IBQuery, LCLType, Variants, LCLProc, LazUTF8; |
151 |
|
|
152 |
|
{ TIBLookupControlLink } |
153 |
|
|
317 |
|
var |
318 |
|
iSelStart: Integer; // char position |
319 |
|
sCompleteText, sPrefixText, sResultText: string; |
318 |
– |
curText: string; |
320 |
|
begin |
321 |
|
if assigned(ListSource) and assigned(ListSource.DataSet) and (ListSource.DataSet is TIBCustomDataSet) |
322 |
|
and ListSource.DataSet.Active then |
323 |
|
begin |
324 |
+ |
FCurText := Text; |
325 |
|
FUpdating := true; |
326 |
|
try |
327 |
|
iSelStart := SelStart;//Capture original cursor position |
328 |
|
if ((iSelStart < UTF8Length(Text)) and |
329 |
|
(cbactEndOfLineComplete in AutoCompleteText)) then |
330 |
|
Exit; |
329 |
– |
curText := Text; |
331 |
|
sPrefixText := UTF8Copy(Text, 1, iSelStart); |
332 |
|
ListSource.DataSet.Active := false; |
333 |
|
ListSource.DataSet.Active := true; |
334 |
< |
Text := curText; |
335 |
< |
if not FExiting and (FForceAutoComplete or Focused) and (Text <> '')then |
334 |
> |
Text := FCurText; |
335 |
> |
if not FExiting and (FForceAutoComplete or Focused) and (FCurText <> '')then |
336 |
|
begin |
337 |
|
if ListSource.DataSet.Active and (ListSource.DataSet.RecordCount > 0) then |
338 |
|
begin |
339 |
|
sCompleteText := ListSource.DataSet.FieldByName(ListField).AsString; |
340 |
< |
if (sCompleteText <> Text) then |
340 |
> |
if (sCompleteText <> FCurText) then |
341 |
|
begin |
342 |
|
sResultText := sCompleteText; |
343 |
|
if ((cbactEndOfLineComplete in AutoCompleteText) and |
351 |
|
SelLength := UTF8Length(Text); |
352 |
|
end; |
353 |
|
KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; |
354 |
+ |
end |
355 |
+ |
else |
356 |
+ |
begin |
357 |
+ |
SelStart := iSelStart; |
358 |
+ |
SelLength := 0; |
359 |
|
end; |
360 |
|
end; |
361 |
|
finally |
362 |
|
FUpdating := false |
363 |
|
end; |
364 |
+ |
FModified := true; |
365 |
|
end; |
366 |
|
end; |
367 |
|
|
368 |
|
procedure TIBLookupComboEditBox.UpdateSQL(Sender: TObject; |
369 |
|
Parser: TSelectSQLParser); |
370 |
|
var FieldPosition: integer; |
371 |
+ |
FilterText: string; |
372 |
|
begin |
373 |
|
if FFiltered then |
374 |
|
begin |
375 |
+ |
if FUpdating then |
376 |
+ |
FilterText := FCurText |
377 |
+ |
else |
378 |
+ |
FilterText := Text; |
379 |
|
if cbactSearchCaseSensitive in AutoCompleteText then |
380 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + ListField + '" Like ''' + |
381 |
< |
SQLSafe(Text) + '%''') |
381 |
> |
SQLSafe(FilterText) + '%''') |
382 |
|
else |
383 |
< |
Parser.Add2WhereClause(GetRelationNameQualifier + 'Upper("' + ListField + '") Like Upper(''' + |
384 |
< |
SQLSafe(Text) + '%'')'); |
383 |
> |
Parser.Add2WhereClause('Upper(' + GetRelationNameQualifier + '"' + ListField + '") Like Upper(''' + |
384 |
> |
SQLSafe(FilterText) + '%'')'); |
385 |
|
|
386 |
< |
end; |
387 |
< |
if cbactSearchAscending in AutoCompleteText then |
388 |
< |
begin |
389 |
< |
FieldPosition := Parser.GetFieldPosition(ListField); |
378 |
< |
if FieldPosition = 0 then Exit; |
386 |
> |
if cbactSearchAscending in AutoCompleteText then |
387 |
> |
begin |
388 |
> |
FieldPosition := Parser.GetFieldPosition(ListField); |
389 |
> |
if FieldPosition = 0 then Exit; |
390 |
|
|
391 |
< |
Parser.OrderByClause := IntToStr(FieldPosition) + ' ascending'; |
391 |
> |
Parser.OrderByClause := IntToStr(FieldPosition) + ' ascending'; |
392 |
> |
end; |
393 |
|
end; |
394 |
|
end; |
395 |
|
|
553 |
|
ActiveChanged(nil); |
554 |
|
end; |
555 |
|
|
556 |
+ |
procedure TIBLookupComboEditBox.UpdateData(Sender: TObject); |
557 |
+ |
begin |
558 |
+ |
inherited UpdateData(Sender); |
559 |
+ |
FModified := false; |
560 |
+ |
end; |
561 |
+ |
|
562 |
|
constructor TIBLookupComboEditBox.Create(TheComponent: TComponent); |
563 |
|
begin |
564 |
|
inherited Create(TheComponent); |
577 |
|
if assigned(FDataLink) then FDataLink.Free; |
578 |
|
if assigned(FIBLookupControlLink) then FIBLookupControlLink.Free; |
579 |
|
if assigned(FTimer) then FTimer.Free; |
580 |
+ |
Application.RemoveAsyncCalls(self); |
581 |
|
inherited Destroy; |
582 |
|
end; |
583 |
|
|
591 |
|
FForceAutoComplete := false; |
592 |
|
end; |
593 |
|
CheckAndInsert; |
594 |
+ |
if FModified then |
595 |
+ |
Change; {ensure Update} |
596 |
|
inherited EditingDone; |
597 |
|
end; |
598 |
|
|