본문 바로가기
Delphi Tip/+Tip

안드로이드에서 MessagDlg 사용방법(주의 점)

by MonoSoft 2022. 3. 11.
728x90
반응형

안드로이드에서 MessagDlg 사용방법(주의 점)


Blockin dialogs not implemented on this platform.




❑ 원인




안드로이드에서는 블로킹 대화상자를 지원하지 않습니다.

하지만 컴파일 시 오류가 나지 않기 때문에 구현 시 주의가 필요합니다.


❑ 해결방안


ACloseDialogProc 파라메터가 있는 MessageDlg 함수를 이용해야 합니다.

ACloseDialogProc은 MessageDlg에서 버튼을 누른 이후의 동작을 가진 익명메소드 입니다.

아래 예제를 참고하세요.


unit uMain;

interface

uses

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls;

type

TMessageAlertsForm = class(TForm)

ToolBar1: TToolBar;

Label1: TLabel;

procedure btnStandardAlertClick(Sender: TObject);

procedure btnMultiButtonAlertClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

MessageAlertsForm: TMessageAlertsForm;

implementation

{$R *.fmx}

{$R *.LgXhdpiPh.fmx ANDROID}

procedure ShowMessage(const TheMessage:String);

begin

MessageDlg(TheMessage, TMsgDlgType.mtInformation, [TMsgDlgBtn.mbOk], 0,

procedure(const AResult: TModalResult)

begin

end

);

end;

procedure TMessageAlertsForm.btnStandardAlertClick(Sender: TObject);

begin

{ Show a standard alert with a single OK button }

ShowMessage('Hello World!');

end;

// In Rad Studio XE7, InputBox, InputQuery, and MessageDlg support a new

// optional parameter, <ACloseDialogProc>.

// Calls that include this new parameter work on all platforms, including

// Android. This new optional parameter allows you to provide an anonymous

// method that is called when the dialog box closes. When you call these

// methods using this new parameter, your call is blocking in desktop platforms

// and non-blocking in mobile platforms.

// If you need to execute code after your dialog box

// closes, use this new parameter to ensure that your application

// works as expected on all supported platforms.

procedure TMessageAlertsForm.btnMultiButtonAlertClick(Sender: TObject);

begin

{ Show a multiple-button alert that triggers different code blocks according to

your input }

MessageDlg('Choose a button:', System.UITypes.TMsgDlgType.mtInformation,

[

System.UITypes.TMsgDlgBtn.mbYes,

System.UITypes.TMsgDlgBtn.mbNo,

System.UITypes.TMsgDlgBtn.mbCancel

], 0,

// Use an anonymous method to make sure the acknowledgment appears as expected.

procedure(const AResult: TModalResult)

begin

case AResult

of

{ Detect which button was pushed and show a different message }

mrYES:

ShowMessage('You chose Yes');

mrNo:

ShowMessage('You chose No');

mrCancel:

ShowMessage('You chose Cancel');

end;

end

)

end;

end.


해당 이슈는 블로킹 형태의 대화상자(InputBox, InputQuery, MessageDlg, ShowMessage) 모두가 해당 됩니다.



참고


http://community.embarcadero.com/index.php/blogs/entry/xe7-dialog-box-methods-support-anonymous-methods-to-handle-their-closing

샘플코드 - http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE7/Object%20Pascal/Mobile%20Snippets/MessageAlerts/uMain.pas#l89

RAD Studio Demo Code / Code / [r1960] /branches/RadStudio_XE7/Obje...

sourceforge.net


A 404 Error has Occurred

sourceforge.net

728x90
반응형

댓글