views:

311

answers:

2

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 UserId: Integer): TLoginInfo;

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

+1  A: 

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;
Alin Sfetcu
RPC is not a way to get rid of type safety...
ldsandon
@ldsandon: this has nothing to do with *get rid of type safety* it`s a working solution for that problem. If you have a better solution please, by all means, post it.
Alin Sfetcu
You have to marshal/unmarshal data properly. How depends on what kind of Datasnap your using. For the last flavour, see my answer.
ldsandon
@ldsandon: care to explain why using JSON is the *better/properly* solution ? P.S. i`m a weekend programmer and this is helping me learn more :)
Alin Sfetcu
That's the way the "new" Datasnap itself uses to marshal/unmarshal data and transmit them. Out of the box it knows how to marshal standard types - user defined types needs to be registered.DCOM uses another way, including type libraries and custom marshal code. Of course you can transmit everything in a binary buffer - but you lose many checks.
ldsandon