Delphi 如何在FireMonkey应用程序中手动显示/不显示虚拟键盘?

Delphi 如何在FireMonkey应用程序中手动显示/不显示虚拟键盘?,delphi,firemonkey,Delphi,Firemonkey,为了开发视频游戏,最近我尝试使用基于FMX的Delphi编写了一个DirectUI组件库,现在我已经完成了按钮、标签、复选框,并且在演示运行时它们看起来非常完美。 但是,当我编写编辑/备忘控件并将其设置为焦点时,我希望手动显示虚拟键盘,因此我编写以下代码: procedure ShowHideVirtualKeyboard(const AControl: TFmxObject; Show: Boolean); var Svc: IFMXVirtualKeyboardService; begi

为了开发视频游戏,最近我尝试使用基于FMX的Delphi编写了一个DirectUI组件库,现在我已经完成了按钮、标签、复选框,并且在演示运行时它们看起来非常完美。 但是,当我编写编辑/备忘控件并将其设置为焦点时,我希望手动显示虚拟键盘,因此我编写以下代码:

procedure ShowHideVirtualKeyboard(const AControl: TFmxObject; Show: Boolean);
var
  Svc: IFMXVirtualKeyboardService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, Svc) then
  begin
    if Show then
      Svc.ShowVirtualKeyboard(AControl)
    else
      Svc.HideVirtualKeyboard;
  end;
end;
它可以在Windows上运行,但在Android上失败了。我查看了FMX源代码,发现该控件必须派生自TControl。 那么,如果我的组件是从TInterfacedObject(即:TDxBaseControl=class(TInterfacedObject))派生的,那么可以手动使虚拟键盘可见吗?
多谢各位

如果只需要解决继承问题,那么使用基于组合的
适配器设计模式
。你可以想象它就像一种包装纸。然后容器类可以继承自
t控件
,包含的容器类可以继承自
TInterfacedObject
。容器(包装器)可以将其调用委托给包含的接口

IMyInterface = interface
  ['{5360279B-4E38-4844-BD46-234CDC873D8C}']
  procedure foo( x_ : integer );
end;

TMyInterfaceImpl = class ( TInterfacedObject, IMyInterface )
  public
    procedure foo( x_ : integer );
end;

TMyInterfaceAdapter = class ( TControl )
  private
    // Fields
    fMyInterface : IMyInterface;

  public
    constructor Create( owner_ : TComponent; myInterface_ : IMyInterface );

    procedure foo( x_ : integer );

end;


procedure TMyInterfaceImpl.foo( x_ : integer );
begin
  //...
end;

constructor TMyComponentAdapter.Create( owner_ : TComponent; myInterface_ : IMyInterface );
begin
  if ( myInterface_ <> NIL ) then
  begin
    inherited Create( owner_ );
    fMyInterface := myInterface_;
  end else
    raise Exception.Create( 'Invalid input parameter value! (myInterface_)' );
end

procedure TMyComponentAdapter.foo( x_ : integer );
begin
  fMyInterface.foo( x_ );
end;
TForm1 = class ( TForm )
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    fMyInterfaceAdapter : TMyInterfaceAdapter;
end;

procedure TForm1.FormCreate(Sender : TObject);
begin
  fMyInterfaceAdapter := TMyInterfaceAdapter.Create( owner, TMyInterfaceImpl.Create );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  fMyInterfaceAdapter.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //...
  fMyInterfaceAdapter.foo( 5 );
  //...
end;