允许键盘输入到FireMonkey TPopup中嵌套的FireMonkey TEdit [英] Allowing keyboard input to a FireMonkey TEdit nested inside a FireMonkey TPopup

查看:831
本文介绍了允许键盘输入到FireMonkey TPopup中嵌套的FireMonkey TEdit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力得到一个FireMonkey 嵌套在FireMonkey TPopup 中以接收键盘输入的FireMonkey。发生在桌面和移动项目中,尽管后者是我感兴趣的:


  1. 创建一个新的FMX项目。 / p>


  2. TButton TPopup 添加到表单,以及 TEdit TPopup


  3. 将弹出的展示位置属性设置为 plCenter 及其 PlacementTarget Button1


  4. 处理按钮的 OnClick 事件通过将弹出的 IsOpen 属性设置为 True


  5. 运行项目,点击/点击按钮,然后尝试在编辑控件中输入文字。


任何想法?当然,正确的答案是:不支持键盘输入,但文档不会说任何一种方式。

解决方案

键盘输入似乎在TPopup上不起作用。
一个简单的解决方案是使用TForm作为弹出窗体:

  unit Popup; 

接口

使用
System.SysUtils,System.Types,System.UITypes,System.Classes,System.Variants,
FMX.Types, FMX.Graphics,FMX.Controls,FMX.Forms,FMX.Dialogs,FMX.StdCtrls,FMX.Edit;

type
TfmPopup = class(TForm)
Edit1:TEdit;
Panel1:TPanel;
procedure FormDeactivate(Sender:TObject);
procedure FormKeyDown(Sender:TObject; var Key:Word; var KeyChar:Char; Shift:TShiftState);
private
protected
public
end;

var
fmPopup:TfmPopup;

实现

{$ R * .fmx}

程序TfmPopup.FormDeactivate(发件人:TObject);
开始
关闭;
结束

程序TfmPopup.FormKeyDown(发件人:TObject; var Key:Word; var KeyChar:Char; Shift:TShiftState);
begin
如果Key = vkEscape然后开始
关闭;
结束
结束

结束。

表单资源:

 对象fmPopup:TfmPopup 
Left = 0
顶部= 0
BorderStyle =无
Caption ='Form1'
ClientHeight = 94
ClientWidth = 142
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [桌面,iPhone,iPad]
OnDeactivate = FormDeactivate
OnKeyDown = FormKeyDown
DesignerMobile = False
DesignerWidth = 0
DesignerHeight = 0
DesignerDeviceName =''
DesignerOrientation = 0
DesignerOSVersion =''
对象Panel1:TPanel
对齐=客户端
高度= 94.000000000000000000
宽度= 142.000000000000000000
TabOrder = 1
对象Edit1:TEdit
Touch.InteractiveGestures = [LongTap ,DoubleTap]
TabOrder = 1
Position.X = 20.000000000000000000
Position.Y = 32.000000000000000000
宽度= 100.0000000000000 00000
高度= 22.000000000000000000
结束
结束
结束

当然你可以改进这个简单的例子:
不要在这个表单上放置TEdit,而是继承这个表单并将编辑放在那里。
例如:

  TfmMyPopup = class(TfmPopup)
Edit1:TEdit;
private
protected
public
end;

使用某些功能(如TPopup)改进TfmPopup的基类:
例如。放置。
可以使用TfmPopup中未显示的TPopup来使用TPopup的放置例程,而无需重写此代码。


I'm struggling to get a FireMonkey TEdit nested inside a FireMonkey TPopup to receive keyboard input. Happens both for desktop and mobile projects, though it's the latter I'm interested in:

  1. Create a new FMX project.

  2. Add a TButton and a TPopup to the form, and a TEdit to the TPopup.

  3. Set the popup's Placement property to plCenter and its PlacementTarget to Button1.

  4. Handle the button's OnClick event by setting the popup's IsOpen property to True.

  5. Run the project, click/tap the button, and try to enter text in the edit control.

Any ideas? The correct answer may of course be: keyboard input isn't supported, but the documentation doesn't say either way.

解决方案

Keyboard Input seems not to work on TPopup. An easy solution is to use a TForm as popup form:

unit Popup;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Edit;

type
  TfmPopup = class(TForm)
    Edit1: TEdit;
    Panel1: TPanel;
    procedure FormDeactivate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
  private
  protected
  public
  end;

var
  fmPopup: TfmPopup;

implementation

{$R *.fmx}

procedure TfmPopup.FormDeactivate(Sender: TObject);
begin
  Close;
end;

procedure TfmPopup.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if Key = vkEscape then begin
    Close;
  end;
end;

end.

The form resources:

object fmPopup: TfmPopup
  Left = 0
  Top = 0
  BorderStyle = None
  Caption = 'Form1'
  ClientHeight = 94
  ClientWidth = 142
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop, iPhone, iPad]
  OnDeactivate = FormDeactivate
  OnKeyDown = FormKeyDown
  DesignerMobile = False
  DesignerWidth = 0
  DesignerHeight = 0
  DesignerDeviceName = ''
  DesignerOrientation = 0
  DesignerOSVersion = ''
  object Panel1: TPanel
    Align = Client
    Height = 94.000000000000000000
    Width = 142.000000000000000000
    TabOrder = 1
    object Edit1: TEdit
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      TabOrder = 1
      Position.X = 20.000000000000000000
      Position.Y = 32.000000000000000000
      Width = 100.000000000000000000
      Height = 22.000000000000000000
    end
  end
end

Of course you can improve this simple example: Do not place the TEdit on this form but inherit this form and place the edit there. E.g.:

TfmMyPopup = class(TfmPopup)
  Edit1: TEdit;
private
protected
public
end;

Improve the base class of TfmPopup with some features like TPopup: E.g. placement. May you can use a never shown TPopup within TfmPopup to use the placement routines of the TPopup without rewriting this code.

这篇关于允许键盘输入到FireMonkey TPopup中嵌套的FireMonkey TEdit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆