加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 10:04:06 所属栏目:大数据 来源:网络整理
导读:在程序开发过程中,我不小心注意到在类中声明的所有类型都具有全局可见性. 我一直认为他们的可见性只限于类,除非类型被引用类类型名称,如TMyClass.TMytype.Value; 我在这里做的事情真的错了,如下结构: unit MyTest;interfacetype TMyTest = class constructo
在程序开发过程中,我不小心注意到在类中声明的所有类型都具有全局可见性.

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

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

unit MyTest;

interface

type 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读