作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下之间的语义差异是什么:
RttiType.TypeKind 和 RttiType.Name ?
我问是因为原则上不能从名称推断出 TypeKind 吗?
最佳答案
TRttiType
的 TypeKind
和 Name
属性是完全不同的东西。
TypeKind
告诉您您拥有哪种类型。这可以是 TTypeKind
枚举类型中定义的 23 个不同选项之一。Name
告诉您您的类型。这是一个字符串,有无限数量的可能值。 不同的类型(通常)具有不同的名称,但可能具有相同的TypeKind
。例如,考虑这个简单的演示。
program RttiDemo;
{$APPTYPE CONSOLE}
uses
Rtti;
procedure Main;
var
Context: TRttiContext;
TObjectType, TInterfacedObjectType: TRttiType;
begin
TObjectType := Context.GetType(TObject);
TInterfacedObjectType := Context.GetType(TInterfacedObject);
Writeln(TObjectType.Name);
Writeln(TInterfacedObjectType.Name);
Assert(TObjectType.TypeKind=TInterfacedObjectType.TypeKind);
end;
begin
Main;
Readln;
end.
输出为:
TObjectTInterfacedObject
因此,您无法从类型 name 推断出类型 kind,因为 kind 和 name 是完全不同的东西。
关于delphi - RttiType.TypeKind 和 RttiType.Name 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16907411/
以下之间的语义差异是什么: RttiType.TypeKind 和 RttiType.Name ? 我问是因为原则上不能从名称推断出 TypeKind 吗? 最佳答案 TRttiType 的 Type
我是一名优秀的程序员,十分优秀!