gpt4 book ai didi

delphi - RttiType.TypeKind 和 RttiType.Name 之间有什么区别?

转载 作者:行者123 更新时间:2023-12-03 18:22:17 24 4
gpt4 key购买 nike

以下之间的语义差异是什么:

RttiType.TypeKind 和 RttiType.Name ?

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

最佳答案

TRttiTypeTypeKindName 属性是完全不同的东西。

  • 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com