31 |
|
|
32 |
|
uses |
33 |
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls, |
34 |
< |
ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet, LCLVersion; |
34 |
> |
ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet; |
35 |
|
|
36 |
|
type |
37 |
|
|
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; |
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, LazUTF8; |
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); |
190 |
– |
var ActiveState: boolean; |
198 |
|
begin |
199 |
|
FTimer.Interval := 0; |
200 |
|
FFiltered := Text <> ''; |
345 |
|
sCompleteText := ListSource.DataSet.FieldByName(ListField).AsString; |
346 |
|
if (sCompleteText <> FCurText) then |
347 |
|
begin |
348 |
+ |
KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; |
349 |
|
sResultText := sCompleteText; |
350 |
|
if ((cbactEndOfLineComplete in AutoCompleteText) and |
351 |
|
(cbactRetainPrefixCase in AutoCompleteText)) then |
355 |
|
end; |
356 |
|
Text := sResultText; |
357 |
|
SelStart := iSelStart; |
358 |
< |
SelLength := UTF8Length(Text); |
358 |
> |
SelLength := UTF8Length(Text) - iSelStart; |
359 |
|
end; |
352 |
– |
KeyValue := ListSource.DataSet.FieldByName(KeyField).AsVariant; |
360 |
|
end |
361 |
|
else |
362 |
|
begin |
367 |
|
finally |
368 |
|
FUpdating := false |
369 |
|
end; |
370 |
+ |
FModified := true; |
371 |
|
end; |
372 |
|
end; |
373 |
|
|
512 |
|
SelectAll; |
513 |
|
end |
514 |
|
else |
515 |
+ |
if AutoComplete and (Style <> csDropDownList) then |
516 |
|
begin |
517 |
< |
FTimer.Interval := 0; |
518 |
< |
if (IsEditableTextKey(Key) or (Key = VK_BACK)) |
519 |
< |
and AutoComplete and (Style <> csDropDownList) and |
520 |
< |
(not (cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then |
517 |
> |
if (Key = VK_BACK) or (Key = VK_DELETE) then |
518 |
> |
begin |
519 |
> |
if SelStart = 0 then |
520 |
> |
begin |
521 |
> |
SelStart := UTF8Length(Text); |
522 |
> |
SelLength := 0; |
523 |
> |
end; |
524 |
> |
FTimer.Interval := 0; |
525 |
> |
end |
526 |
> |
else |
527 |
> |
if IsEditableTextKey(Key) and |
528 |
> |
(not(cbactEndOfLineComplete in AutoCompleteText) or (SelStart = UTF8Length(Text))) then |
529 |
> |
begin |
530 |
> |
FTimer.Interval := 0; |
531 |
|
FTimer.Interval := FKeyPressInterval; |
532 |
+ |
end; |
533 |
|
end; |
534 |
|
end; |
535 |
|
|
549 |
|
|
550 |
|
procedure TIBLookupComboEditBox.SetItemIndex(const Val: integer); |
551 |
|
begin |
552 |
+ |
if Val > 0 then |
553 |
+ |
FCurText := ''; |
554 |
|
inherited SetItemIndex(Val); |
555 |
|
FLastKeyValue := KeyValue; |
556 |
|
end; |
573 |
|
ActiveChanged(nil); |
574 |
|
end; |
575 |
|
|
576 |
+ |
procedure TIBLookupComboEditBox.UpdateData(Sender: TObject); |
577 |
+ |
begin |
578 |
+ |
inherited UpdateData(Sender); |
579 |
+ |
if FCurText <> '' then |
580 |
+ |
Text := FCurText + Text; |
581 |
+ |
FModified := false; |
582 |
+ |
end; |
583 |
+ |
|
584 |
|
constructor TIBLookupComboEditBox.Create(TheComponent: TComponent); |
585 |
|
begin |
586 |
|
inherited Create(TheComponent); |
613 |
|
FForceAutoComplete := false; |
614 |
|
end; |
615 |
|
CheckAndInsert; |
616 |
+ |
FCurText := ''; |
617 |
+ |
if FModified then |
618 |
+ |
Change; {ensure Update} |
619 |
|
inherited EditingDone; |
620 |
|
end; |
621 |
|
|