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

在程序开发过程中,我不小心注意到在类中声明的所有类型都具有全局可见性.

我一直认为他们的可见性只限于类,除非类型被引用类类型名称,如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.

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...