XE3 essay 6:superobject can also contain a "method" in a JSON object

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.