Superobject's JSON object can also contain "methods", which is interesting; The format of the method is:
procedure Method (constvar result:isuperobject); ///In addition, this is an enumeration of its data types: Tsupertype = (Stnull, Stboolean, stdouble, stint, Stobject, Starray, ststring, Stmethod);
Test code:
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Keyboard;typeTForm1 =class(Tform) Button1:tbutton; Button2:tbutton;procedureButton1Click (Sender:tobject);procedureButton2click (Sender:tobject);End;varForm1:tform1;Implementation{$R *.DFM}usesSuperobject;//Method 1; Parameter list is OK, but no parameters are used hereprocedureMETHOD1 (Constthis, params:isuperobject;varResult:isuperobject);beginShowMessage (' Hello ');End;//Method 2; The second parameter is used here; the second one here is the first one that is calledprocedureMETHOD2 (Constthis, params:isuperobject;varResult:isuperobject);beginShowMessage (Params.asjson);End;Method 3; The first parameter is used, the first parameter value is used without passing, it represents the object that uses the methodprocedureMETHOD3 (Constthis, params:isuperobject;varResult:isuperobject);beginShowMessage (This.asjson);End;//Method 4; The third parameter is used here, which is the return value at the time of the call, and if it is not assigned a value, the call will have no return valueprocedureMETHOD4 (Constthis, params:isuperobject;varResult:isuperobject);beginResult: = this; Result.merge (Params, True);{Merge}End;//The first method of useprocedureTform1.button1click (Sender:tobject);varJo:isuperobject;beginJO: = SO (' {' X ': ' Y '} '); Jo. m[' JM1 ']: = @Method1; Jo. m[' jm2 ']: = @Method2; Jo. m[' jm3 ']: = @Method3; Jo. m[' JM4 ']: = @Method4; Jo.call (' JM1 ');//HelloJo.call (' jm2 ', SO (' {' A ': ' B '} '));//{"A": "B"}Jo.call (' jm2 ',' {' A ': ' B '} ');//{"A": "B"}Jo.call (' jm3 ');//{"X": "Y"}Jo.call (' JM4 ',' {' B ': null} '); ShowMessage (Jo. Asjson);//{"X": "Y", "B": null}End;//second method of useprocedureTform1.button2click (Sender:tobject);varT,jo:isuperobject;beginJO: = SO (' {' X ': ' Y '} '); Jo. m[' JM1 ']: = @Method1; Jo. m[' jm2 ']: = @Method2; Jo. m[' jm3 ']: = @Method3; Jo. m[' JM4 ']: = @Method4; jo[' jm1 () '];//Hellojo[' jm2 ('+' {' A ': ' B '} '+' ) '];//{"A": "B"}jo[' jm2 ({a:b}) '];//{"A": "B"}jo[' jm3 () '];//{"X": "Y"}jo[' Jm4 ('+' {' B ': null} '+' ) ']; ShowMessage (Jo. Asjson);//{"X": "Y", "B": null}End;End.
XE3 essay 6:superobject can also contain a "method" in a JSON object