Register host types directly from RTTI: AddType(PTypeInfo) and AddRecordWithRTTI#311
Open
TetzkatLipHoka wants to merge 1 commit into
Open
Register host types directly from RTTI: AddType(PTypeInfo) and AddRecordWithRTTI#311TetzkatLipHoka wants to merge 1 commit into
TetzkatLipHoka wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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