解决DATASNAP远程方法参数超过32个的问题

时间:2020-12-01 07:06:39
群里有位同仁提出他有一个DATASNAP远程方法超过了32个参数,然后DELPHI编译通不过,提示方法参数不能超过32个,问怎么办?于是群内同仁纷纷出主意,我说用OLEVARINAT数组,有人说用RECORD,我又说别说用RECORD,连自定义的类也是可以的。于是我想到了实现,用SUPEROBJECT序列RECORD或者CLASS为JSON的字符串挺方便的,中间件收到客户端传来的JSON字符串再还原为RECORD或者CLASS。
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, superobject;
 
type
  TPerson = record
    id: Integer;
    name: string;
  end;
 
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
var
  s: string;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  p: TPerson;
  i: ISuperObject;
begin
  p.id :=1;
  p.name :='name';
  i := SO();
  i.I['id']:=p.id;
  i.S['name']:=p.name;
  s := i.AsString;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
var
  i: ISuperObject;
begin
  i := SO(s);
  ShowMessage(i['id'].AsString);
  showmessage(i['name'].AsString);
end;
 
end.