jvcllaz: Fix usage of utf8 in JvDBLookup controls. Based on patch by Michal Gawrycki. Issue #38494.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7972 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-02-15 21:35:31 +00:00
parent b84c87da3c
commit d8500d93ae
2 changed files with 43 additions and 42 deletions

View File

@ -15,7 +15,6 @@
<XPManifest> <XPManifest>
<DpiAware Value="True"/> <DpiAware Value="True"/>
</XPManifest> </XPManifest>
<Icon Value="0"/>
</General> </General>
<BuildModes Count="1"> <BuildModes Count="1">
<Item1 Name="Default" Default="True"/> <Item1 Name="Default" Default="True"/>
@ -25,7 +24,6 @@
</PublishOptions> </PublishOptions>
<RunParams> <RunParams>
<FormatVersion Value="2"/> <FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams> </RunParams>
<RequiredPackages Count="3"> <RequiredPackages Count="3">
<Item1> <Item1>

View File

@ -39,7 +39,6 @@ unit JvDBLookup;
interface interface
uses uses
//{$IFDEF WINDOWS}Windows,{$ENDIF}
Variants, Classes, Graphics, Controls, Forms, DB, DBCtrls, Variants, Classes, Graphics, Controls, Forms, DB, DBCtrls,
LMessages, LCLType, LCLIntf, LCLProc, Themes, LMessages, LCLType, LCLIntf, LCLProc, Themes,
JvThemes, JvDBUtils; JvThemes, JvDBUtils;
@ -142,7 +141,7 @@ type
function LocateDisplay: Boolean; function LocateDisplay: Boolean;
function ValueIsEmpty(const S: string): Boolean; function ValueIsEmpty(const S: string): Boolean;
function StoreEmpty: Boolean; function StoreEmpty: Boolean;
procedure ProcessSearchKey(Key: Char); procedure ProcessSearchKey(Key: TUTF8Char);
procedure UpdateKeyValue; procedure UpdateKeyValue;
procedure SelectKeyValue(const Value: string); procedure SelectKeyValue(const Value: string);
procedure SetDataFieldName(const Value: string); procedure SetDataFieldName(const Value: string);
@ -267,7 +266,7 @@ type
procedure ListLinkActiveChanged; override; procedure ListLinkActiveChanged; override;
procedure ListLinkDataChanged; override; procedure ListLinkDataChanged; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override; procedure UTF8KeyPress(var Key: TUTF8Char); override;
procedure Loaded; override; procedure Loaded; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override; X, Y: Integer); override;
@ -368,7 +367,7 @@ type
procedure CMHintShow(var Msg: TLMessage); message CM_HINTSHOW; procedure CMHintShow(var Msg: TLMessage); message CM_HINTSHOW;
protected protected
procedure Click; override; procedure Click; override;
procedure KeyPress(var Key: Char); override; procedure UTF8KeyPress(var Key: TUTF8Char); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
end; end;
@ -382,7 +381,7 @@ type
FCombo: TJvLookupControl; FCombo: TJvLookupControl;
FList: TJvPopupDataList; FList: TJvPopupDataList;
procedure Deactivate; override; procedure Deactivate; override;
procedure KeyPress(var Key: char); override; procedure UTF8KeyPress(var Key: TUTF8Char); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure DoShow; override; procedure DoShow; override;
procedure DoClose(var CloseAction: TCloseAction); override; procedure DoClose(var CloseAction: TCloseAction); override;
@ -474,7 +473,7 @@ type
procedure DataLinkUpdateData; override; procedure DataLinkUpdateData; override;
procedure Paint; override; procedure Paint; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override; procedure UTF8KeyPress(var Key: TUTF8Char); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
@ -725,7 +724,7 @@ type
implementation implementation
uses uses
DBConst, SysUtils, Math, {MultiMon,} DBConst, SysUtils, Math, LazUTF8, {MultiMon,}
{JclSysInfo,} {JclSysInfo,}
JvJCLUtils, JvJVCLUtils, JvTypes, JvConsts, JvResources{, JclSysUtils}; JvJCLUtils, JvJVCLUtils, JvTypes, JvConsts, JvResources{, JclSysUtils};
@ -1205,17 +1204,21 @@ begin
end; end;
end; end;
procedure TJvLookupControl.ProcessSearchKey(Key: Char); procedure TJvLookupControl.ProcessSearchKey(Key: TUTF8Char);
var var
TickCount: Int64; TickCount: Int64;
S: string; S: string;
L: Integer;
begin begin
S := ''; S := '';
if (FDisplayField <> nil) then if (FDisplayField <> nil) then
case Key of begin
Tab, Esc: L := Length(Key);
FSearchText := ''; if (L = 1) and (Key[1] in [Tab, Esc]) then
Backspace, #32..High(Char): FSearchText := ''
else if (L = 1) and (Key[1] < #32) and (Key[1] <> Backspace) then
exit
else
if CanModify then if CanModify then
begin begin
if not FPopup then if not FPopup then
@ -1226,7 +1229,7 @@ begin
SearchTickCount := TickCount; SearchTickCount := TickCount;
end; end;
if Key = Backspace then if Key = Backspace then
S := Copy(FSearchText, 1, Length(FSearchText) - 1) S := UTF8Copy(FSearchText, 1, UTF8Length(FSearchText)-1)
else else
if Length(FSearchText) < 32 then if Length(FSearchText) < 32 then
S := FSearchText + Key; S := FSearchText + Key;
@ -1799,9 +1802,9 @@ begin
end; end;
end; end;
procedure TJvDBLookupList.KeyPress(var Key: Char); procedure TJvDBLookupList.UTF8KeyPress(var Key: TUTF8Char);
begin begin
inherited KeyPress(Key); inherited UTF8KeyPress(Key);
ProcessSearchKey(Key); ProcessSearchKey(Key);
end; end;
@ -2477,21 +2480,21 @@ begin
TJvDBLookupCombo(FCombo).InvalidateText; TJvDBLookupCombo(FCombo).InvalidateText;
end; end;
procedure TJvPopupDataList.KeyPress(var Key: Char); procedure TJvPopupDataList.UTF8KeyPress(var Key: TUTF8Char);
begin begin
inherited KeyPress(Key); inherited UTF8KeyPress(Key);
if Assigned(FCombo) and TJvDBLookupCombo(FCombo).FListVisible then if Assigned(FCombo) and TJvDBLookupCombo(FCombo).FListVisible then
TJvDBLookupCombo(FCombo).InvalidateText; TJvDBLookupCombo(FCombo).InvalidateText;
end; end;
{ TJvPopupDataListForm } { TJvPopupDataListForm }
procedure TJvPopupDataListForm.KeyPress(var Key: char); procedure TJvPopupDataListForm.UTF8KeyPress(var Key: TUTF8Char);
begin begin
inherited KeyPress(Key); inherited UTF8KeyPress(Key);
if Assigned(FCombo) then if Assigned(FCombo) then
begin begin
TJvDBLookupCombo(FCombo).KeyPress(Key); TJvDBLookupCombo(FCombo).UTF8KeyPress(Key);
if TJvDBLookupCombo(FCombo).FListVisible then if TJvDBLookupCombo(FCombo).FListVisible then
TJvDBLookupCombo(FCombo).InvalidateText; TJvDBLookupCombo(FCombo).InvalidateText;
end; end;
@ -2989,9 +2992,9 @@ begin
FDataListForm.FList.KeyDown(Key, Shift); FDataListForm.FList.KeyDown(Key, Shift);
end; end;
procedure TJvDBLookupCombo.KeyPress(var Key: Char); procedure TJvDBLookupCombo.UTF8KeyPress(var Key: TUTF8Char);
begin begin
inherited KeyPress(Key); inherited UTF8KeyPress(Key);
if FListVisible then if FListVisible then
begin begin
if TabSelects and IsDropDown and (Key = Tab) then if TabSelects and IsDropDown and (Key = Tab) then
@ -3003,7 +3006,7 @@ begin
Key := #0; Key := #0;
end end
else else
FDataListForm.FList.KeyPress(Key) FDataListForm.FList.UTF8KeyPress(Key)
end end
else else
begin begin
@ -3011,7 +3014,7 @@ begin
begin begin
DropDown; DropDown;
if FListVisible then if FListVisible then
FDataListForm.FList.KeyPress(Key); FDataListForm.FList.UTF8KeyPress(Key);
end end
else else
if (Key = Esc) and FEscapeKeyReset then if (Key = Esc) and FEscapeKeyReset then