E2003未声明的标识符:' mtConfirmation'和' mbOK'

时间:2015-03-04 09:53:34

标签: delphi compiler-errors dialog delphi-xe7

从我可以告诉他们这两个应该是在我正在使用的System.UITypes,但我仍然得到错误消息。我该如何解决这个问题?

我基于http://docwiki.embarcadero.com/CodeExamples/XE7/en/FileExists_(Delphi)

中的示例中的消息对话框

原始代码来自http://delphi.radsoft.com.au/2013/11/checking-for-an-internet-connection-on-mobile-devices-with-delphi-xe5/

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

uses
  NetworkState;

procedure TForm1.Button1Click(Sender: TObject);
var
  NS: TNetworkState;
begin
  NS := TNetworkState.Create;
  try
    if not NS.IsConnected then begin
      MessageDlg(('No connection'), mtConfirmation, [mbOK], 0);
    end else if NS.IsWifiConnected then begin
      MessageDlg(('Wifi connection'), mtConfirmation, [mbOK], 0);
    end else if NS.IsMobileConnected then begin
      MessageDlg(('Mobile connection'), mtConfirmation, [mbOK], 0);
    end;
    Label2.Text := NS.CurrentSSID;
  finally
    NS.Free;
  end;
end;

end.

1 个答案:

答案 0 :(得分:5)

此单元中的枚举类型为scoped。注意

的使用
{$SCOPEDENUMS ON}

就在单位的顶部。

  

$ SCOPEDENUMS指令启用或禁用范围的使用   Delphi代码中的枚举。更具体地说,$ SCOPEDENUMS会影响   仅限新枚举的定义,并仅控制添加   枚举值符号的全局范围。

     

在{$ SCOPEDENUMS ON}状态下,枚举具有作用域和枚举   值不会添加到全局范围。指定一个成员   scoped enum,你必须包含枚举的类型。

这意味着需要完全确定值的范围,例如

TMsgDlgType.mtConfirmation

并且喜欢这个

TMsgDlgBtn.mbOK

等等。

相关问题