View Issue Details

IDProjectCategoryView StatusLast Update
0038322pas2jsrtlpublic2021-01-11 00:04
Reporterhenrique Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformPas2JsOSWindows 
Summary0038322: RTTI info for record types
DescriptionI started implementing rtti information for the "Record" types, but I had a problem.

In the definition of the record type, in the TypInfo unit, there should be a field called "Record", but in the file "RTL.js" there is no reference to this.

Is there any implementation missing or have not found the record reference, to get his information?

I've attach the implementation I started doing, to the JSON serializer I'm implementing.
TagsNo tags attached.
Fixed in Revision
Attached Files

Activities

henrique

2021-01-06 14:19

reporter  

0001-Come-ando-a-implementa-o-do-RTTI-Record.patch (3,085 bytes)   
From eb18be73605de4028e8b98ae8392330f783f9b12 Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Wed, 6 Jan 2021 09:52:10 -0300
Subject: [PATCH] =?UTF-8?q?Come=C3=A7ando=20a=20implementa=C3=A7=C3=A3o=20?=
 =?UTF-8?q?do=20RTTI=20Record.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 packages/rtl/rtti.pas | 44 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/packages/rtl/rtti.pas b/packages/rtl/rtti.pas
index 9a516a1..6dbf186 100644
--- a/packages/rtl/rtti.pas
+++ b/packages/rtl/rtti.pas
@@ -248,7 +248,7 @@ type
     FMethods: TRttiMethodArray;
     FProperties: TRttiPropertyArray;
   protected
-    function GetAncestor: TRttiStructuredType; virtual; abstract;
+    function GetAncestor: TRttiStructuredType; virtual;
     function GetStructTypeInfo: TTypeInfoStruct;
   public
     constructor Create(ATypeInfo: PTypeInfo);
@@ -274,9 +274,10 @@ type
     function GetMetaClassType: TClass;
   protected
     function GetAncestor: TRttiStructuredType; override;
+    function GetIsInstance: boolean; override;
   public
     constructor Create(ATypeInfo: PTypeInfo);
-    function GetIsInstance: boolean; override;
+
     property ClassTypeInfo: TTypeInfoClass read GetClassTypeInfo;
     property MetaClassType: TClass read GetMetaClassType;
   end;
@@ -296,6 +297,19 @@ type
     property InterfaceTypeInfo: TTypeInfoInterface read GetInterfaceTypeInfo;
   end;
 
+  { TRttiRecordType }
+
+  TRttiRecordType = class(TRttiStructuredType)
+  private
+    function GetRecordTypeInfo: TTypeInfoRecord;
+  protected
+    function GetIsRecord: Boolean; override;
+  public
+    constructor Create(ATypeInfo: PTypeInfo);
+
+    property RecordTypeInfo: TTypeInfoRecord read GetRecordTypeInfo;
+  end;
+
   { TRttiOrdinalType }
 
   TRttiOrdinalType = class(TRttiType)
@@ -838,6 +852,11 @@ begin
   Result := FProperties;
 end;
 
+function TRttiStructuredType.GetAncestor: TRttiStructuredType;
+begin
+  Result := nil;
+end;
+
 function TRttiStructuredType.GetStructTypeInfo: TTypeInfoStruct;
 begin
   Result:=TTypeInfoStruct(FTypeInfo);
@@ -944,6 +963,25 @@ begin
   Result := GRttiContext.GetType(InterfaceTypeInfo.Ancestor) as TRttiStructuredType;
 end;
 
+{ TRttiRecordType }
+
+function TRttiRecordType.GetRecordTypeInfo: TTypeInfoRecord;
+begin
+  Result := TTypeInfoRecord(FTypeInfo);
+end;
+
+function TRttiRecordType.GetIsRecord: Boolean;
+begin
+  Result := True;
+end;
+
+constructor TRttiRecordType.Create(ATypeInfo: PTypeInfo);
+begin
+  if not (TTypeInfo(ATypeInfo) is TTypeInfoClass) then
+    raise EInvalidCast.Create('');
+  inherited Create(ATypeInfo);
+end;
+
 { TRTTIContext }
 
 class constructor TRTTIContext.Init;
@@ -984,7 +1022,7 @@ var
     nil, // tkMethod
     TRttiType, // tkArray
     TRttiDynamicArrayType, // tkDynArray
-    TRttiType, // tkRecord
+    TRttiRecordType, // tkRecord
     TRttiInstanceType, // tkClass
     TRttiType, // tkClassRef
     TRttiType, // tkPointer
-- 
2.29.2.windows.2

Mattias Gaertner

2021-01-11 00:04

manager   ~0128257

The 'record' should be '$record'. I fixed it and added a comment that this is only available for records with class vars.

I applied your patch.

Issue History

Date Modified Username Field Change
2021-01-06 14:19 henrique New Issue
2021-01-06 14:19 henrique File Added: 0001-Come-ando-a-implementa-o-do-RTTI-Record.patch
2021-01-07 09:47 Mattias Gaertner Assigned To => Mattias Gaertner
2021-01-07 09:47 Mattias Gaertner Status new => assigned
2021-01-11 00:04 Mattias Gaertner Status assigned => resolved
2021-01-11 00:04 Mattias Gaertner Resolution open => fixed
2021-01-11 00:04 Mattias Gaertner Note Added: 0128257