Delphi Prism,如何声明枚举的常量有界数组
我收到编译错误
[错误 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.