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

Fri*_*iso 1 delphi dialog compiler-errors 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.
Run Code Online (Sandbox Code Playgroud)

Dav*_*nan 5

此单元中的枚举类型是作用域.注意使用

{$SCOPEDENUMS ON}
Run Code Online (Sandbox Code Playgroud)

就在单元的顶部.

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

在{$ SCOPEDENUMS ON}状态中,枚举是作用域的,并且枚举值不会添加到全局范围.要指定作用域枚举的成员,必须包含枚举的类型.

这意味着需要完全限定值,如下所示

TMsgDlgType.mtConfirmation
Run Code Online (Sandbox Code Playgroud)

并且喜欢这个

TMsgDlgBtn.mbOK
Run Code Online (Sandbox Code Playgroud)

等等.