本文介绍了RttiType.TypeKind和RttiType.Name有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间的语义区别是什么?

What is the semantic difference between:

RttiType.TypeKind和RttiType.Name吗?

RttiType.TypeKind and RttiType.Name ?

我问因为原则上不能从名称推断出TypeKind?

I ask because couldn't one in principle infer the TypeKind from the Name?

推荐答案

是一个字符串。 是枚举类型,适合在循环或 case 语句中使用。它们根本不一样,在实际使用中,从字符串中推断根本不是一回事。

RTTIType.Name is a string. RTTI.TypeKind is an enumerated type that is suitable for use in a loop or case statement. They're not the same at all, and "inferring from a string" is not the same thing at all when it comes to actual use. It's much more clear, concise, and efficient to write

case TypeKind of
  tkInteger, tkInt64: DoSomething;
  tkEnumeration: DoThisInstead;
...

比写

if (Name = 'tkInteger') or (Name = 'tkInt64') then
  DoSomething
else if (Name = 'tkEnumeration') then
  DoThisInstead
...

这篇关于RttiType.TypeKind和RttiType.Name有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 04:13