我很难让FireMonkey TEdit嵌套在FireMonkey TPopup中,以接收键盘输入。桌面和移动项目都会出现这种情况,尽管我对后者很感兴趣:
TButton和TPopup,向TPopup添加TEdit。Placement属性设置为plCenter,将其PlacementTarget设置为Button1。IsOpen属性设置为True来处理按钮的True事件。有什么想法吗?正确的答案当然可能是:键盘输入不受支持,但文档没有说明这两种方式。
发布于 2014-11-27 15:43:31
键盘输入似乎不适用于TPopup。一个简单的解决方案是使用TForm作为弹出表单:
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.表格资源:
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当然,您可以改进这个简单的示例:不要将TEdit放在此表单上,而是继承此表单并将编辑放在那里。例如:
TfmMyPopup = class(TfmPopup)
Edit1: TEdit;
private
protected
public
end;使用一些特性来改进TfmPopup的基类,如TPopup:例如放置。您可以使用TfmPopup中从未显示的TfmPopup来使用TPopup的放置例程,而无需重写这段代码。
发布于 2015-04-03 13:54:19
有同样的问题,但固定的行为很少覆盖。将格式更改为TFormStyle.Normal并处理OnDeactivate事件。
TPopup2 = class(TPopup)
protected
function CreatePopupForm: TFmxObject; override;
end;
TPopupForm2 = class(TCustomPopupForm)
private
procedure OnDeactivateEvent(Sender: TObject);
public
constructor CreateNew(AOwner: TComponent; Dummy: NativeInt = 0); override;
end;
function TPopup2.CreatePopupForm: TFmxObject;
var
NewStyle: TStyleBook;
NewForm: TPanelForm;
begin
NewForm := nil;
try
if not Assigned(StyleBook) and Assigned(Scene) then
NewStyle := Scene.GetStyleBook
else
NewStyle := StyleBook;
NewForm := TPopupForm2.Create(Self, NewStyle, PlacementTarget);
except
FreeAndNil(NewForm);
Raise;
end;
Result := NewForm;
end;
constructor TPopupForm2.CreateNew(AOwner: TComponent; Dummy: NativeInt);
begin
inherited;
BeginUpdate;
try
FormStyle := TFormStyle.Normal;
BorderStyle := TFmxFormBorderStyle.None;
Fill.Kind := TBrushKind.None;
Transparency := True;
OnDeactivate := OnDeactivateEvent;
finally
EndUpdate;
end;
end;
procedure TPopupForm2.OnDeactivateEvent(Sender: TObject);
begin
Close;
end;发布于 2014-01-02 20:46:41
使用Popup1.popup(true)而不是更改isOpen属性
https://stackoverflow.com/questions/20890373
复制相似问题