Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

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).

–jeroen


Filed under: Agile, Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Development, DUnit, Software Development, Unit Testing

Viewing all articles
Browse latest Browse all 1725

Trending Articles