Skip to content

Register host types directly from RTTI: AddType(PTypeInfo) and AddRecordWithRTTI#311

Open
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:feature/rtti-addtype
Open

Register host types directly from RTTI: AddType(PTypeInfo) and AddRecordWithRTTI#311
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:feature/rtti-addtype

Conversation

@TetzkatLipHoka

Copy link
Copy Markdown

Importing host types previously meant hand-writing AddTypeS
declarations that had to be kept in sync with the Delphi type. The
compiler can now derive them from RTTI:

Sender.AddType(TypeInfo(TFruits)); // set of TFruit
Sender.AddType(TypeInfo(TIntArr)); // array of Integer
Sender.AddType(TypeInfo(TMyEvent)); // procedure(...) of object
Sender.AddType(TypeInfo(TFull)); // packed record (Delphi 2010+)

AddType(PTypeInfo) covers the classic RTTI kinds - integers (all ord
sizes), chars, all string kinds, floats, enums, Variant, Int64/UInt64
(UInt64 detected via its inverted MinInt64Value/MaxInt64Value pattern),
sets, dynamic arrays and method pointers (signature reconstructed from
the ParamList RTTI). Element types of sets/arrays are registered
recursively; sets/dynarrays/methods are excluded under FPC where the
TTypeData layouts differ.

On Delphi 2010+ extended RTTI adds tkRecord via AddRecordWithRTTI and
named static array types. Records must be packed: field offsets are
verified one by one (including tail padding) and a padded layout is
rejected with a clear error, because script records are packed and a
mismatched layout would corrupt data on host interop. Fields with
anonymous types (inline 'array[0..7] of X') have no RTTI and are
rejected with a message naming the field; generic names such as
TArray<System.Byte> are sanitized to valid script identifiers.

TypInfo moves to the interface uses for PTypeInfo in the public
signatures; the Rtti unit stays implementation-only (the protected
helpers take untyped pointers).

🤖 Generated with Claude Code

…ordWithRTTI

Importing host types previously meant hand-writing AddTypeS
declarations that had to be kept in sync with the Delphi type. The
compiler can now derive them from RTTI:

  Sender.AddType(TypeInfo(TFruits));     // set of TFruit
  Sender.AddType(TypeInfo(TIntArr));     // array of Integer
  Sender.AddType(TypeInfo(TMyEvent));    // procedure(...) of object
  Sender.AddType(TypeInfo(TFull));       // packed record (Delphi 2010+)

AddType(PTypeInfo) covers the classic RTTI kinds - integers (all ord
sizes), chars, all string kinds, floats, enums, Variant, Int64/UInt64
(UInt64 detected via its inverted MinInt64Value/MaxInt64Value pattern),
sets, dynamic arrays and method pointers (signature reconstructed from
the ParamList RTTI). Element types of sets/arrays are registered
recursively; sets/dynarrays/methods are excluded under FPC where the
TTypeData layouts differ.

On Delphi 2010+ extended RTTI adds tkRecord via AddRecordWithRTTI and
named static array types. Records must be packed: field offsets are
verified one by one (including tail padding) and a padded layout is
rejected with a clear error, because script records are packed and a
mismatched layout would corrupt data on host interop. Fields with
anonymous types (inline 'array[0..7] of X') have no RTTI and are
rejected with a message naming the field; generic names such as
TArray<System.Byte> are sanitized to valid script identifiers.

TypInfo moves to the interface uses for PTypeInfo in the public
signatures; the Rtti unit stays implementation-only (the protected
helpers take untyped pointers).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant