delphi – 所有人都可以看到私人类型?

delphi – 所有人都可以看到私人类型?,第1张

概述在程序开发过程中,我不小心注意到在类中声明的所有类型都具有全局可见性. 我一直认为他们的可见性只限于类,除非类型被引用类类型名称,如TMyClass.TMytype.Value; 我在这里做的事情真的错了,如下结构: unit MyTest;interfacetype TMyTest = class constructor Create; strict private 在程序开发过程中,我不小心注意到在类中声明的所有类型都具有全局可见性.

我一直认为他们的可见性只限于类,除非类型被引用类类型名称,如TMyClass.TMytype.Value;

我在这里做的事情真的错了,如下结构:

unit MyTest;interfacetype TMyTest  = class    constructor Create;    strict private        type TMyType = ( Nul,SLEEP );end;implementation// ...

导致使用此(MyTest)单元的其他单元中的冲突.

如果单位有睡眠(100);调用,它将与TMyTest.TMyType.SLEEP冲突和预防冲突是为什么我首先将SLEEP封装在类和TMyType之中.

任何建议的解决方法?

解决方法 这实际上是设计的.您的枚举值具有单位或全局范围.他们不是私人的,因为他们不是课堂的一部分.它们在全球范围内.

您可以通过包含scoped enums指令来安排枚举值具有本地范围:

{$ScopEDENUMS ON}

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.

总结

以上是内存溢出为你收集整理的delphi – 所有人都可以看到私人类型?全部内容,希望文章能够帮你解决delphi – 所有人都可以看到私人类型?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1276838.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存