焦点编辑 Firemonkey 项目中的字段时虚拟键盘不显示

VirtualKeyboard not Show when focus Edit fields in Firemonkey project

我在 Delphi 10 Seattle 有一个 Firemonkey 多设备项目,用户可以在应用程序启动时获得一个屏幕。这里用户需要填写2个字段。但是当我点击编辑字段时,虚拟键盘没有显示。如果我在开始时跳过此屏幕并稍后调用它,则会显示虚拟键盘。这也是以同样的方式完成的。

我找到了某种解决方案: 当我单击编辑字段时,我自己调用 show VirtualKeyboard。唯一的问题是光标未显示在编辑字段中。

有没有办法自己放置光标?或者谁知道如何用其他方式解决虚拟键盘不显示的问题?

Android 和 iOS 都有问题

在下面的代码中,您可以看到创建的初始表单。问题是在 ConnectFromProfile 方法中调用 actCreateNewProfileExecute 时。在那里它将调用一个新的表单。在那种形式(TfrmProfile)中,虚拟键盘没有显示。我也用另一个动作调用这个表单,然后它工作正常。

procedure TfrmNocoreDKS.FormCreate(Sender: TObject);
begin
  Inherited;
  System.SysUtils.FormatSettings.ShortDateFormat := 'dd/mm/yyyy';
  CheckPhone;
  ConnectfromProfile;
  if not Assigned(fProfileAction) then
    ConnectDatabase
  Else
    lstDocuments.Enabled := False;

{$IFDEF ANDROID}
  ChangeComboBoxStyle;
{$ENDIF}
end;

procedure TfrmNocoreDKS.ConnectfromProfile;
begin
  fdmProfileConnection := TdmConnection.Create(nil);
  fdmProfileConnection.OpenProfileDb;
  fdmProfileConnection.LoadProfiles;

  if fdmProfileConnection.Profiles.Count = 0 then
  begin // Createdefault Profile
    fProfileAction := actCreateNewProfileExecute;
  end
  else if fdmProfileConnection.Profiles.Count = 1 then
  begin // one profile load connection;
    fProfileAction := nil;
    fCurrentProfile := fdmProfileConnection.Profiles.Items[0];
  end
  else
  begin // multiple profiles choose connection;
    fProfileAction := SelectProfileOnStartUp;
  end;
end;

procedure TfrmNocoreDKS.FormShow(Sender: TObject);
begin
  if Assigned(fProfileAction) then
    fProfileAction(Self);
end;

procedure TfrmNocoreDKS.actCreateNewProfileExecute(Sender: TObject);
var
  profilename, databasename, pathname: string;
  prf: TfrmProfile;
begin
  prf := TfrmProfile.Create(nil);
  prf.Data := fdmProfileConnection.Profiles;
  prf.ShowModal(
    procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOk then
      begin
        profilename := prf.edtProfilename.Text;
        databasename := prf.edtDatabaseName.Text;

{$IFDEF IOS}
        pathname := System.IOUtils.TPath.GetDocumentsPath;
{$ENDIF}
{$IFDEF ANDROID}
        pathname := System.IOUtils.TPath.GetDocumentsPath;
{$ENDIF}
{$IFDEF WIN32}
        pathname := ExtractFilePath(ParamStr(0)) + '\Data';
{$ENDIF}
        FDSQLiteBackup1.Database := System.IOUtils.TPath.Combine(pathname,
          'default.sqlite3'); // Default Database
        FDSQLiteBackup1.DestDatabase := System.IOUtils.TPath.Combine(pathname,
          databasename + '.sqlite3');
        FDSQLiteBackup1.Backup;
        fdmProfileConnection.AddProfile(databasename + '.sqlite3', profilename);
        fdmProfileConnection.LoadProfiles;
        fCurrentProfile := fdmProfileConnection.Profiles.Items[0];
        connectDatabase;
      end else
        Application.Terminate;
    end);
end;

不要在 MainForm.OnCreate/OnShow 中显示任何附加表格。在 "launch screen".

的 iOS 9.2 freeze 应用程序上尝试此操作

取而代之的是异步显示新表单,如下所示:

procedure TForm4.FormShow(Sender: TObject);
begin
  TTask.Run(procedure
    begin
      TThread.Synchronize(nil, procedure // work with visual controls - only throught Synchronize or Queue
        begin
          Form5:=TForm5.Create(Application);
          Form5.ShowModal;
        end)
    end);
end;

当然,您可以将此代码分离到外部程序:

procedure ShowMyForm;
begin
  Form5:=TForm5.Create(Application);
  Form5.ShowModal;
end;

procedure TaskProc;
begin
  TThread.Synchronize(nil, ShowMyForm);
end;

procedure TForm4.FormShow(Sender: TObject);
begin
  TTask.Run(TaskProc);
end;

========

另一种方式 - 不要使用任何附加表格。使用 Align = Contents 创建框架并将其(在运行时)放在 MainForm 上。在所有需要的操作之后 - 隐藏或释放(由于 ARC 不要忘记将 nil 设置为帧变量)此帧。