Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure why you get that error. The following seems to work for me, in Delphi XE:</p> <pre><code>program Project1; {$APPTYPE CONSOLE} uses SysUtils, Classes, Contnrs, Generics.Defaults, Generics.Collections, DbxJson, DbxJsonReflect; type TTestObject = class(TObject) aList : TStringList; function Marshal : TJSonObject; public constructor Create; destructor Destroy; override; end; TTestObjectList&lt;T:TTestObject,constructor&gt; = class(TObjectList&lt;T&gt;) function Marshal: TJSonObject; constructor Create; end; { TTestObject } constructor TTestObject.Create; begin inherited Create; aList := TStringList.Create; aList.Add('one'); aList.Add('two'); aList.Add('three'); end; destructor TTestObject.Destroy; begin aList.Free; inherited; end; function TTestObject.Marshal: TJSonObject; var Marshal: TJSONMarshal; begin Marshal := TJSONMarshal.Create(TJSONConverter.Create); try Marshal.RegisterConverter(TStringList, function (Data: TObject): TListOfStrings var I, Count: Integer; begin Count := TStringList(Data).Count; SetLength(Result, Count); for I := 0 to Count - 1 do Result[I] := TStringList(Data)[I]; end ); Result := Marshal.Marshal(Self) as TJSONObject; finally Marshal.Free; end; end; { TTestObjectList&lt;T&gt; } constructor TTestObjectList&lt;T&gt;.Create; begin inherited Create; Add(T.Create); Add(T.Create); end; function TTestObjectList&lt;T&gt;.Marshal: TJSonObject; var Marshal: TJsonMarshal; begin Marshal := TJSONMarshal.Create(TJSONConverter.Create); try Marshal.RegisterConverter(TTestObject, function (Data: TObject): TObject begin Result := T(Data).Marshal; end ); Result := Marshal.Marshal(Self) as TJSONObject; finally Marshal.Free; end; end; procedure Main; var aTestobj : TTestObject; aList : TTestObjectList&lt;TTestObject&gt;; aJsonObject : TJsonObject; begin aTestObj := TTestObject.Create; aJsonObject := aTestObj.Marshal; Writeln(aJsonObject.ToString); Writeln; aList := TTestObjectList&lt;TTestObject&gt;.Create; aJsonObject := aList.Marshal; Writeln(aJsonObject.ToString); Readln; end; begin try Main; except on E: Exception do begin ExitCode := 1; Writeln(Format('[%s] %s', [E.ClassName, E.Message])); end; end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload