From 1ad2c82b1761fcee62c9ac739bb01654f1d9bec9 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Sat, 27 Aug 2011 15:44:58 +0000 Subject: [PATCH] fix locate string values in PopUp forms - now RxDBLookupCombo find values for string fields on type his on keyboard git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1839 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/rxlookup.pas | 10 +++---- components/rx/rxpopupunit.pas | 54 ++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/components/rx/rxlookup.pas b/components/rx/rxlookup.pas index 30379e144..5fad7c8fa 100644 --- a/components/rx/rxlookup.pas +++ b/components/rx/rxlookup.pas @@ -246,7 +246,7 @@ type procedure OnInternalClosePopup(AResult:boolean);virtual; procedure SetEnabled(Value: Boolean); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; - procedure KeyPress(var Key: char); override; + procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override; procedure SetParent(AParent: TWinControl); override; procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: Integer); override; procedure DoPositionButton; virtual; @@ -1294,13 +1294,13 @@ begin end; -procedure TRxCustomDBLookupCombo.KeyPress(var Key: char); +procedure TRxCustomDBLookupCombo.UTF8KeyPress(var UTF8Key: TUTF8Char); begin - if not (PopupVisible) and ((Key in [#32..#255]) or (Key=#8)) then + if not (PopupVisible) and ((UTF8Key >= #32) or (UTF8Key = #8)) then ShowList; - inherited KeyPress(Key); + inherited UTF8KeyPress(UTF8Key); if PopupVisible then - FRxPopUpForm.KeyPress(Key); + FRxPopUpForm.UTF8KeyPress(UTF8Key); end; procedure TRxCustomDBLookupCombo.SetParent(AParent: TWinControl); diff --git a/components/rx/rxpopupunit.pas b/components/rx/rxpopupunit.pas index 4fa108902..61a34e94d 100644 --- a/components/rx/rxpopupunit.pas +++ b/components/rx/rxpopupunit.pas @@ -51,11 +51,13 @@ type FLookupDisplayIndex: integer; FLookupDisplayField:string; procedure ClearFind; - procedure FindNextChar(AChar:Char); + procedure FindNextChar(UTF8Key: TUTF8Char); +// procedure FindNextUTF8Char(UTF8Key: TUTF8Char); procedure FindPriorChar; procedure SetLookupDisplayIndex(const AValue: integer); protected - procedure KeyPress(var Key: char); dynamic; + procedure KeyPress(var Key: char); override; + procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; property LookupDisplayIndex:integer read FLookupDisplayIndex write SetLookupDisplayIndex; end; @@ -217,7 +219,7 @@ type procedure DoSetFieldsFromString(FL:string); procedure DoSetFieldsFromColList; public - procedure KeyPress(var Key: char); override; + procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override; constructor CreatePopUp(AOwner: TComponent; APopUpFormOptions:TPopUpFormOptions; AFieldList:string; BtnWidtn:integer); destructor Destroy; override; @@ -232,7 +234,7 @@ function ShowRxDBPopUpForm(AControl:TWinControl; ADataSet:TDataSet; procedure FillPopupWidth(APopUpFormOptions:TPopUpFormOptions; ARxPopUpForm:TPopUpForm); implementation -uses dbutils, math; +uses dbutils, math, LCLProc; function ShowRxDBPopUpForm(AControl:TWinControl; ADataSet:TDataSet; AOnPopUpCloseEvent:TPopUpCloseEvent; APopUpFormOptions:TPopUpFormOptions; @@ -333,10 +335,10 @@ begin Invalidate; end; -procedure TPopUpForm.KeyPress(var Key: char); +procedure TPopUpForm.UTF8KeyPress(var UTF8Key: TUTF8Char); begin - inherited KeyPress(Key); - FGrid.KeyPress(Key); + inherited UTF8KeyPress(UTF8Key); + FGrid.UTF8KeyPress(UTF8Key); end; procedure TPopUpForm.GridDblClick(Sender: TObject); @@ -808,7 +810,22 @@ begin DataSource.DataSet.First; end; -procedure TPopUpGrid.FindNextChar(AChar: Char); +procedure TPopUpGrid.FindNextChar(UTF8Key: TUTF8Char); +var + F:string; +begin + FFindLine:=FFindLine + UTF8Key; + if DatalinkActive then + if DataSetLocateThrough(DataSource.DataSet, FLookupDisplayField, FFindLine, [loCaseInsensitive, loPartialKey]) then + begin + TPopUpForm(Owner).WControl.Caption:=FFindLine; + TPopUpForm(Owner).WControl.Repaint; + end + else + FFindLine:=F; +end; +{ +procedure TPopUpGrid.FindNextUTF8Char(UTF8Key: TUTF8Char); var F:string; begin @@ -822,14 +839,15 @@ begin else FFindLine:=F; end; - +} procedure TPopUpGrid.FindPriorChar; var F:string; begin if FFindLine = '' then exit; F:=FFindLine; - Delete(FFindLine, Length(FFindLine), 1); + UTF8Delete(FFindLine, UTF8Length(FFindLine), 1); + //Delete(FFindLine, Length(FFindLine), 1); if DatalinkActive then if (FFindLine<>'') then begin @@ -876,6 +894,22 @@ begin ClearFind; end; +procedure TPopUpGrid.UTF8KeyPress(var UTF8Key: TUTF8Char); +begin + inherited UTF8KeyPress(UTF8Key); +{ if (Columns[FLookupDisplayIndex].Field.DataType<>ftString) and not (Key in ['0'..'9']) then + Exit + else} + if UTF8Key=#32 then + FindNextChar(UTF8Key) + else + if UTF8Key>#32 then + FindNextChar(UTF8Key) + else + if UTF8Key = #8 then + ClearFind; +end; + procedure TPopUpGrid.KeyDown(var Key: Word; Shift: TShiftState); begin if Key = VK_DELETE then