From 9e69dd979838928a8206d177b901be72906f8666 Mon Sep 17 00:00:00 2001 From: Juha Date: Fri, 21 Apr 2023 12:45:31 +0300 Subject: [PATCH] LCL-CustomDrawn: Improve TEdit key press events. Issue #40221, patch by Alexey Torgashin. --- lcl/interfaces/customdrawn/customdrawnprivate.pas | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lcl/interfaces/customdrawn/customdrawnprivate.pas b/lcl/interfaces/customdrawn/customdrawnprivate.pas index bcf33be060..7a95139583 100644 --- a/lcl/interfaces/customdrawn/customdrawnprivate.pas +++ b/lcl/interfaces/customdrawn/customdrawnprivate.pas @@ -288,7 +288,7 @@ end; procedure CallbackKeyChar(AWindowHandle: TCDForm; AKeyData: Word; AChar: TUTF8Char); var lTarget: TWinControl; - lCharCode: Word = 0; + lCharCode: Word; begin lTarget := AWindowHandle.GetFocusedControl(); {$ifdef VerboseCDEvents} @@ -296,17 +296,20 @@ begin {$endif} if lTarget = nil then Exit; // Fixes a crash - if Length(AChar) = 1 then lCharCode := Word(AChar[1]); + if Length(AChar) = 1 then + lCharCode := Byte(AChar[1]) + else + lCharCode:=0; -// if lCharCode <> 0 then LCLSendCharEvent(lTarget, lCharCode, AKeyData, True, False, True); - LCLSendUTF8KeyPress(lTarget, AChar, False); + if AChar<>'' then LCLSendUTF8KeyPress(lTarget, AChar, False); + if lCharCode <> 0 then LCLSendCharEvent(lTarget, lCharCode, AKeyData, True, False, True); // If this is a interface control, send the message to the main LCL control too if IsIntfControl(lTarget) then begin lTarget := lTarget.Parent; -// if lCharCode <> 0 then LCLSendCharEvent(lTarget, lCharCode, AKeyData, True, False, True); - LCLSendUTF8KeyPress(lTarget, AChar, False); + if AChar<>'' then LCLSendUTF8KeyPress(lTarget, AChar, False); + if lCharCode <> 0 then LCLSendCharEvent(lTarget, lCharCode, AKeyData, True, False, True); end; end;