Delphi Prism,如何声明枚举的常量有界数组

发布于 2024-12-13 11:07:23 字数 611 浏览 4 评论 0原文

我收到编译错误

[错误 1 ​​(PE114) 从类型“ConsoleApplication”使用的“ConsoleApplication.MyEnum 的数组[0..1]”。 必须是 public D:\PrismProjects\ConsoleApplication\ConsoleApplication\Program.pas 14 42 ConsoleApplication] :

当我尝试编译以下代码时,

namespace ConsoleApplication;

interface

type
  ConsoleApp = class
    public
      class method Main(args: array of string);
  end;

  MyEnum = (F, T);

const
  EnumOfBool: array[boolean] of MyEnum = [MyEnum.F, MyEnum.T];

implementation

  class method ConsoleApp.Main(args: array of string);
  begin
    Console.WriteLine('Hello World.');
  end;
end.

I get a compilation error

[Error 1 (PE114) Type "array[0..1] of ConsoleApplication.MyEnum" used from type "ConsoleApplication." must be public D:\PrismProjects\ConsoleApplication\ConsoleApplication\Program.pas 14 42 ConsoleApplication]

when I try to compile the following code:

namespace ConsoleApplication;

interface

type
  ConsoleApp = class
    public
      class method Main(args: array of string);
  end;

  MyEnum = (F, T);

const
  EnumOfBool: array[boolean] of MyEnum = [MyEnum.F, MyEnum.T];

implementation

  class method ConsoleApp.Main(args: array of string);
  begin
    Console.WriteLine('Hello World.');
  end;
end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半步萧音过轻尘 2024-12-20 11:07:23

MyEnum 在哪里定义的?我很确定无论在哪里,它都没有标记为公共(如错误消息所示),但它保留默认可见性(在 .NET 中是私有的)。

那么 RRUZ 的评论是正确的,你应该避免全局声明。 Oxygene 编译器需要创建一个(不可见的、自动生成的)类,并将其包含为静态(类)成员,因为 .NET 不允许全局声明,所以您应该首先“正确”地执行它。

Where is MyEnum defined? I'm pretty sure wherever that is, it is not marked as public (as the error message suggests), but it's left on the default visibility (which is private in .NET).

Then RRUZ is correct in his comment, you should avoid global declarations. The Oxygene compiler needs to create a (invisible, auto-generated) class containing this as a static (class) member anyways because .NET does not allow for global declarations, so you should do it 'right' in the first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文