What is the semantic difference between:
RttiType.TypeKind and RttiType.Name ?
I ask because couldn't one in principle infer the TypeKind from the Name?
The TypeKind and Name properties of TRttiType are completely different things.
TypeKind tells you what sort of type you have. This can be one of the 23 different options define in the TTypeKind enumerated type.Name tells you which type you have. This is a string and there are an unlimited number of possible values. Different types will (usually) have different names, but may have the same TypeKind. For example consider this simple demonstration.
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.
The output is:
TObject TInterfacedObject
So, you cannot infer the type kind from the type name since kind and name are quite different things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With