1

in superobject, ISuperObject has a method called "AsMethod", what does it do ? how do i use it ?

lets say i have this code, how can i marshall to json the signature itself (with params) so i can easily have it ready for the SOInvoke ? thanks everyone.

for example, lets say i have procedure hey('sup', 45, false);, can i have it marshalled as {method: "hey", Arg0: "sup", Arg1: 45, Arg2: false} ?

procedure TForm1.Test(const MyType: TMyType; const s: string);
begin
  case MyType of
    mtTry:
      showmessage('Try');
    mtHey:
      showmessage('Hey');
  else
    showmessage('Else');
  end;

  showmessage(s);
end;

procedure TForm1.Button1Click(Sender: TObject);
type
  TTestProc = procedure (const MyType: TMyType; const s: string) of object;
var
  Ctx: TSuperRttiContext;
  Sig: TTestProc;
begin
   Ctx := TSuperRttiContext.Create;

   Ctx.AsJson<TTestProc>(Sig(mtHey, 'hey'));


  // SOInvoke(Self, 'test', SO('{MyType: 1, Param: "shit"}'));

   Ctx.Free;
end;
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • Have you read the documentation for SuperObject? – Jerry Dodge Apr 24 '13 at 18:27
  • @JerryDodge I could not find any doc about SuperObject except this (https://code.google.com/p/superobject/wiki/first_steps), which still isn't enough for me. –  Apr 24 '13 at 18:28
  • Hmm, it only mentions it once, and that's only in a list of ways to access, but with no explanation whatsoever...? – Jerry Dodge Apr 24 '13 at 18:31
  • I'm assuming you can send a javascript method through a JSON object to be implemented further at its destination – Jerry Dodge Apr 24 '13 at 18:34
  • @JerryDodge what do you mean by a JS method ? –  Apr 24 '13 at 18:35
  • JSON is based on Javascript structure, and was originally designed to be used with it. Since Javascript, is, well script, it can be injected somewhere and executed on-the-fly. Therefore, maybe this is an option of sending javascript (basically same as string but meant for script)? – Jerry Dodge Apr 24 '13 at 18:38
  • I don't even see anything in standard JSON documentation about such a data type – Jerry Dodge Apr 24 '13 at 18:40
  • http://www.c-sharpcorner.com/UploadFile/3d39b4/data-types-in-json/ – Jerry Dodge Apr 24 '13 at 18:45
  • 1
    I can see it actually has to do with an unexplained `SUPER_METHOD` conditional, which tells me it's an experimental and unfinished addition to the SuperObject library. – Jerry Dodge Apr 24 '13 at 18:51
  • In the source code (`superobject`): `v1.0: + parser can now evaluate properties and call methods` – Jerry Dodge Apr 24 '13 at 18:52
  • so in short it is not finished ? –  Apr 24 '13 at 18:55
  • Not sure, I see plenty of code, and the source even comes with a test application called `test_prototype` which appears to use it, but no explanations really. I say open that test app and try to see for yourself. – Jerry Dodge Apr 24 '13 at 18:56
  • Yeah, that source is quite interesting, i'll look at it and post feedback here.. –  Apr 24 '13 at 19:07
  • In all cases, your code `Ctx.AsJson(Sig(mtHey, 'hey'))` will compile but NEVER run. Since `Sig` is filled with some random data on the stack, you will get an access violation. – Arnaud Bouchez Apr 25 '13 at 07:21
  • Why not ping the author [Henri Gourvest](http://stackoverflow.com/users/259076/henri-gourvest) ? He certainly has a lot to tell. – menjaraz Apr 29 '13 at 12:36

0 Answers0