7

所有者フォームの中央にモーダルダイアログを表示するのに問題があります。モーダルダイアログを表示するための私のコードは次のとおりです。

procedure TfrmMain.btnOpenSettingsClick(Sender: TObject);
var
  sdSettingsDialog: TdlgSettings;

begin
   sdSettingsDialog := TdlgSettings.Create(Self);
   sdSettingsDialog.Position := TFormPosition.poOwnerFormCenter;

   try
      sdSettingsDialog.ShowModal;
   finally
     sdSettingsDialog.Free;
   end;
end;

デザイナでもPositionプロパティを変更しようとしましたが、ダイアログが中央に配置されていないようです。

ここで何が問題なのか教えてもらえますか?

4

1 に答える 1

8

位置はShowModalによってFireMonkeyに実装されていません。以下のクラスヘルパーを使用すると、ShowModalを呼び出す前にsdSettingsDialog.UpdateFormPositionを使用できます。

type
  TFormHelper = class helper for TForm
    procedure UpdateFormPosition;
  end;

procedure TFormHelper.UpdateFormPosition;
var
  RefForm: TCommonCustomForm;
begin
  RefForm := nil;

  case Position of
    // TFormPosition.poScreenCenter: implemented in FMX.Forms (only one)
    TFormPosition.poOwnerFormCenter:
      if Assigned(Owner) and (Owner is TCommonCustomForm) then
        RefForm := Owner as TCommonCustomForm;
    TFormPosition.poMainFormCenter:
      RefForm := Application.MainForm;
  end;

  if Assigned(RefForm) then
  begin
    SetBounds(
      System.Round((RefForm.Width - Width) / 2) + RefForm.Left,
      System.Round((RefForm.Height - Height) / 2) + RefForm.Top,
      Width, Height);
  end;
end;
于 2011-11-19T16:39:55.833 に答える