2

i'm using this superobject unit in one of my project as an rpc protocol, and inside a remote called procedure (signature has a var Result arg) i want to know how to use that arg...

isn't there a documentation ? thanks.

program test_rpc;

{$IFDEF FPC}
  {$MODE OBJFPC}{$H+}
{$ELSE}
  {$APPTYPE CONSOLE}
{$ENDIF}

uses
  SysUtils, superobject;

procedure controler_method1(const This, Params: ISuperObject; var Result: ISuperObject);
var
  i: Integer;
begin
  write('action called with params ');
  writeln(Params.AsString);

  try
    // How do i use Result arg to return a value ? as if it were a function returning string
    Result
  except
    exit;
  end;
end;

var
  s: ISuperObject;
begin
  s := TSuperObject.Create;
  s.M['controler.action1'] := @controler_method1;
  try
    s['controler.action1("HHAHAH")'];
  finally
    s := nil;
    writeln('Press enter ...');
    readln;
  end;
end.
7
  • Are you sure that you've given us enough information? It's not clear to me what this Result is that you talk of. Do you need to explain more? Are you talking about TSuperMethod = procedure(const This, Params: ISuperObject; var Result: ISuperObject);? And if so, what are you asking about it? Mar 3, 2013 at 12:04
  • Whoops, looks like support forum at progdigy.com/forums is gone
    – Jan Doggen
    Mar 3, 2013 at 12:16
  • @DavidHeffernan: yes that one.. ;]
    – user1803300
    Mar 3, 2013 at 13:05
  • But what is the question? Mar 3, 2013 at 13:07
  • @DavidHeffernan lets say i called a function, how do i return a result ?
    – user1803300
    Mar 3, 2013 at 13:33

1 Answer 1

3

When controler_method1 is called, the var parameter Result is nil. To return something to the caller you need to assign to Result.

Result := TSuperObject.Create;

That's an empty super object. You can now populate it with whatever values you like in the normal way.

Here is a simple demonstration:

program test_rpc;

{$IFDEF FPC}
  {$MODE OBJFPC}{$H+}
{$ELSE}
  {$APPTYPE CONSOLE}
{$ENDIF}

uses
  SysUtils,
  superobject in 'superobject.pas';

procedure controler_method1(const This, Params: ISuperObject;
    var Result: ISuperObject);
begin
  Result := TSuperObject.Create('Foo');
end;

var
  s: ISuperObject;
begin
  s := TSuperObject.Create;
  s.M['controler.action1'] := controler_method1;
  Writeln(s['controler.action1("HHAHAH")'].AsString);
  Readln;
end.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.