The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,087 other followers

Delphi types that cannot be used for TypeInfo

Posted by jpluimers on 2014/03/03

When writing the Spring4D unit tests for GetTypeSize to include as many TTypeKind values, I came across a few types that either did not compile, or were not supported by TypeInfo. I listed them below as I could not find them in the documentation.

I included a test named Test_EnsureAllTTypeKindsCoveredByCallsTo_Test_GetTypeSize_ that verifies that all TTypeKind values except tkUnknown are covered. So future extensions of TTypeKind will make the tests fail.

As a side issue, I really wanted to know if tkUnknown could be emitted by the compiler. It can sort of, for instance by defining discontiguous enumerations, but are incompatible with TypeInfo as well.

Types that do not compile at all:

Types incompatible with the TypeInfo, the compiler will throw an E2134 error “Type ‘%s’ has no type info”:

Finally a few platform dependent things that are kind of obvious, but it is good to note them:

  • Since NativeInt is Integer on 32-bit platforms and Int64 on 64-bit platform*, so the TTypeKind is either tkInteger or tkInt64.
  • Since NativeUInt is Cardinal on 32-bit platforms and UInt64 on 64-bit platform*, so the TTypeKind is  either tkInteger or tkInt64.

Hopefully the * can be replaced with s in the future.

In short, SizeOf isn’t a good function to check for the data size on the stack. SizeOf for instance also fails for Variants (sometimes returning 24 on x64).


2 Responses to “Delphi types that cannot be used for TypeInfo”

  1. sglienke said

    You are wrong on the Boolean types. They all have tkEnumeration as TypeKind.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: