开发者

How to return a record in a DataSnap method

I wish to be able to declare a Data Snap method with the following signature

type
  TLoginInfo = record
    Username: string;
    Password: string;
    LastLogged: DateTime;
  end;

function GetLoginInfo(const开发者_Python百科 UserId: Integer): TLoginInfo;

When I try to call it it says that TLoginInfo is not well known.


If your are using the "new" Datasnap see here:

http://blogs.embarcadero.com/adrian/2009/08/19/json-types-for-server-methods-in-datasnap-2010/ https://blogs.embarcadero.com/json-types-for-server-methods-in-datasnap-2010/ http://www.danieleteti.it/?p=146


store the record into a stream and pass the stream to the DataSnap method

//on server side

function GetLoginInfo(const UserId: Integer): TStream;
begin
  Result := TMemoryStream.Create;
  Result.Write( loginRec, SizeOf(TLoginInfo) )
  Result.Seek(0, TSeekOrigin.soBeginning);
end;

//on client side

procedure TfrmMain.getLogInto( sUser: string);
var
  AStr : TStream;
  loginRec : TLoginInfo;
begin
//  cycleConnection;

  with TMethodsClient.Create( SQLConn.DBXConnection, False ) do begin

    AStr := GetLoginInfo( sUser );
    AStr.Read( loginRec, SizeOf(TLoginInfo) )
    Free;
  end;

  FreeAndNil(AStr);
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜