unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.Edit, FMX.ScrollBox, FMX.Memo, FMX.StdCtrls;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
procedure FormKeyUp(Sender: TObject;
var Key: Word;
var KeyChar: Char; Shift: TShiftState);
procedure Edit1ChangeTracking(Sender: TObject);
procedure Memo1ChangeTracking(Sender: TObject);
procedure Memo1KeyDown(Sender: TObject;
var Key: Word;
var KeyChar: Char; Shift: TShiftState);
procedure HandleKeyEvent(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject;
var Key: Word;
var KeyChar: Char; Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.FMX}
procedure TForm1.FormKeyUp(Sender: TObject;
var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
// HardKeys abrufen
// Key := 0;
// KeyChar := #0;
end;
procedure TForm1.Edit1KeyDown(Sender: TObject;
var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
// Return-key pressed
if (Key = 13)
or (Key = 10)
then
showmessage('
KeyDownEvent Key=' + inttostr(Key) + '
, KeyChar=' + KeyChar);
end;
procedure TForm1.Edit1ChangeTracking(Sender: TObject);
begin
HandleKeyEvent(Sender);
// or define in object inspector + code in onKeyDown-Event!!!
// ... other code
end;
procedure TForm1.Memo1KeyDown(Sender: TObject;
var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
// Return-key pressed
if (Key = 13)
or (Key = 10)
then
showmessage('
KeyDownEvent Key=' + inttostr(Key) + '
, KeyChar=' + KeyChar);
end;
procedure TForm1.Memo1ChangeTracking(Sender: TObject);
begin
HandleKeyEvent(Sender);
// ... other code
end;
procedure TForm1.HandleKeyEvent(Sender: TObject);
var
i: integer;
t:
string;
tempText:
string;
Key: Word;
KeyChar: Char;
begin
{$IFDEF Android}
// Detect #10 and #13 line breaks
Key := 0;
KeyChar := #0;
if (Sender
is TEdit)
then
t := (Sender
as TEdit).Text;
if (Sender
is TMemo)
then
t := (Sender
as TMemo).Text;
// Detect line breaks #10 or #13
tempText := '
';
if Length(t) > 0
then
begin
i := Low(t);
while i <= High(t)
do
begin
if (t[i] = #13)
or (t[i] = #10)
then
begin
Key := ord(t[i]);
// 13 or 10
KeyChar := t[i];
// #13 or #10
end
else
tempText := tempText + t[i];
inc(i);
end;
if (Key <> 0)
then
begin
if (Sender
is TEdit)
then
begin
(Sender
as TEdit).Text := tempText;
if assigned((Sender
as TEdit).OnKeyDown)
then
(Sender
as TEdit).OnKeyDown(Sender, Key, KeyChar, []);
end;
if (Sender
is TMemo)
then
begin
(Sender
as TMemo).Text := tempText;
if assigned((Sender
as TMemo).OnKeyDown)
then
(Sender
as TMemo).OnKeyDown(Sender, Key, KeyChar, []);
end;
end;
end;
{$ENDIF}
end;
end.