Friso
Friso

Reputation: 2438

E2003 Undeclared identifier: 'mtConfirmation' and 'mbOK'

From what I can tell both of those are supposed to be in System.UITypes, which I'm using, but I still get the error message. How can I fix this?

I've based the message dialog from the example in http://docwiki.embarcadero.com/CodeExamples/XE7/en/FileExists_(Delphi)

The original code came from 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.

Upvotes: 1

Views: 2512

Answers (1)

David Heffernan
David Heffernan

Reputation: 613232

The enumerated types in this unit are scoped. Note the use of

{$SCOPEDENUMS ON}

right at the top of the unit.

The $SCOPEDENUMS directive enables or disables the use of scoped enumerations in Delphi code. More specifically, $SCOPEDENUMS affects only definitions of new enumerations, and only controls the addition of the enumeration's value symbols to the global scope.

In the {$SCOPEDENUMS ON} state, enumerations are scoped, and enum values are not added to the global scope. To specify a member of a scoped enum, you must include the type of the enum.

That means that need to fully scope the values, like this

TMsgDlgType.mtConfirmation

and like this

TMsgDlgBtn.mbOK

and so on.

Upvotes: 6

Related Questions