Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As per the comments, here is an example of how you can avoid the problem by handling <code>KeyPress</code> events instead of manually converting <code>KeyDown</code> events. The TNT controls don't provide a <code>WideChar</code> <code>KeyPress</code> event, but it's fairly easy to add. Ideally, you should not put the extensions to <code>TTntMemo</code> and <code>TTntForm</code> in derived classes as I've done here, but instead modify the TNT source code.</p> <p>The form contains two <code>TTntMemo</code> controls. Pressing keys in the first will log the events in the second.</p> <pre><code>unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, TntForms, StdCtrls, TntStdCtrls; type TKeyPressWEvent = procedure(Sender: TObject; var Key: WideChar) of object; TTntMemo = class(TntStdCtrls.TTntMemo) private FOnKeyPressW: TKeyPressWEvent; procedure WMChar(var Msg: TWMChar); message WM_CHAR; protected function DoKeyPressW(var Message: TWMKey): Boolean; procedure KeyPressW(var Key: WideChar); published property OnKeyPressW: TKeyPressWEvent read FOnKeyPressW write FOnKeyPressW; end; TTntForm = class(TntForms.TTntForm) private FOnKeyPressW: TKeyPressWEvent; procedure WMChar(var Msg: TWMChar); message WM_CHAR; protected function DoKeyPressW(var Message: TWMKey): Boolean; procedure KeyPressW(var Key: WideChar); published property OnKeyPressW: TKeyPressWEvent read FOnKeyPressW write FOnKeyPressW; end; TForm1 = class(TTntForm) TntMemo1: TTntMemo; TntMemo2: TTntMemo; procedure FormCreate(Sender: TObject); procedure FormKeyPressW(Sender: TObject; var Key: WideChar); procedure TntMemo1KeyPressW(Sender: TObject; var Key: WideChar); end; var Form1: TForm1; implementation uses TntControls; {$R *.dfm} type TWinControlAccess = class(TWinControl); TTntFormAccess = class(TTntForm); function TntControl_DoKeyPressW(Self: TWinControl; var Message: TWMKey; KeyPressW: Pointer): Boolean; type TKeyPressWProc = procedure(Self: TWinControl; var Key: WideChar); var Form: TCustomForm; Ch: WideChar; begin Result := True; Form := GetParentForm(Self); if (Form &lt;&gt; nil) and (Form &lt;&gt; Self) and Form.KeyPreview then begin if (Form is TTntForm) and TTntFormAccess(Form).DoKeyPressW(Message) then Exit; if TWinControlAccess(Form).DoKeyPress(Message) then Exit; end; if not (csNoStdEvents in Self.ControlStyle) then begin Ch := GetWideCharFromWMCharMsg(Message); TKeyPressWProc(KeyPressW)(Self, Ch); SetWideCharForWMCharMsg(Message, Ch); if Ch = #0 then Exit; end; Result := False; end; { TTntMemo } function TTntMemo.DoKeyPressW(var Message: TWMKey): Boolean; begin Result := TntControl_DoKeyPressW(Self, Message, @TTntMemo.KeyPressW); end; procedure TTntMemo.KeyPressW(var Key: WideChar); begin if Assigned(FOnKeyPressW) then FOnKeyPressW(Self, Key); end; procedure TTntMemo.WMChar(var Msg: TWMChar); begin if not DoKeyPressW(Msg) then inherited; end; { TTntForm } function TTntForm.DoKeyPressW(var Message: TWMKey): Boolean; begin Result := TntControl_DoKeyPressW(Self, Message, @TTntForm.KeyPressW); end; procedure TTntForm.KeyPressW(var Key: WideChar); begin if Assigned(FOnKeyPressW) then FOnKeyPressW(Self, Key); end; procedure TTntForm.WMChar(var Msg: TWMChar); begin if not DoKeyPressW(Msg) then inherited; end; { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin Self.OnKeyPressW := FormKeyPressW; TntMemo1.OnKeyPressW := TntMemo1KeyPressW; end; procedure TForm1.FormKeyPressW(Sender: TObject; var Key: WideChar); begin TntMemo2.Lines.Add(WideString('FormKeyPress: ') + Key); end; procedure TForm1.TntMemo1KeyPressW(Sender: TObject; var Key: WideChar); begin TntMemo2.Lines.Add(WideString('TntMemo1KeyPress: ') + Key); end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload