2011年6月14日火曜日

【Delphi】メッセージダイアログをフォーム中央に表示する

メッセージダイアログをフォームとして受取り、加工した後に表示する。
更新 20230724 : Windows11に対応
function TForm1.ShowConfirmMsg(_msg: string): TModalResult;
  var
    frmMsg: TForm;
begin
  frmMsg := CreateMessageDialog(_msg, mtConfirmation, [mbOK, mbCancel]);
  with frmMsg do begin
    try
      Self.InsertComponent(frmMsg);
      Position := poOwnerFormCenter;
      ShowModal;
    finally
      Free;
    end;
  end;
end;

(久しぶりに使ってみたら文法エラーが出たので Self.InsertComponent を追加しました。)

0 件のコメント: