Delphi Prism and DataSnap Server Method Stream Parameters

Posted by on in Blogs

This post is about using Delphi Prism to pass streams to/from DataSnap server methods.  The sample client that goes along with this post is available here: http://cc.embarcadero.com/item/26874.


This client has the same functionality as the Delphi client described in this post: DataSnap Server Method Stream Parameters.  Here is a screen shot of the two clients running against the same Delphi sample server.



Download the Delphi sample server (and Delphi sample client) here: http://cc.codegear.com/item/26854.   For introductory information about the difference between Delphi and Delphi Prism DataSnap clients see this post: Call DataSnap Server Methods with Delphi Prism.


Stream Parameter Types

This table shows the parameter types and return types in the stream samples. The columns under “Server Parameter” describe the parameter or return type in the Delphi DataSnap servers methods. The “Delphi Type” column shows the corresponding type used in the Delphi client. The “Delphi Prism Type” column shows type used in the Delphi Prism client.





























Server Parameter Client Parameters
Type (default) var out Result Delphi Type Delphi Prism Type
TStream

(in)




TStream System.IO.Stream
TDBXStreamValue

(in/out)


 


 


 

TStream System.IO.Stream


Code Samples


The following code samples show the differences between calling server methods with DbExpress in Delphi compared to ADO.NET in Delphi Prism.















TStream Server Method
function TTestStream.Echo(I: TStream): TStream;
Delphi/DbExpress
function TTestStreamClient.Echo(I: TStream): TStream;
begin
if FEchoCommand = nil then
begin
FEchoCommand := FDBXConnection.CreateCommand;
FEchoCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FEchoCommand.Text := 'TTestStream.Echo';
FEchoCommand.Prepare;
end;
FEchoCommand.Parameters[0].Value.SetStream(I, FInstanceOwner);
FEchoCommand.ExecuteUpdate;
Result := FEchoCommand.Parameters[1].Value.GetStream(FInstanceOwner);
end;
Delphi Prism/ADO.NET
function TTestStreamClient.Echo(I: System.IO.Stream): System.IO.Stream;
begin
if FEchoCommand = nil then
begin
FEchoCommand := FDBXConnection.CreateCommand as TAdoDbxCommand;
FEchoCommand.CommandType := System.Data.CommandType.StoredProcedure;
FEchoCommand.CommandText := 'TTestStream.Echo';
FEchoCommand.Prepare;
end;
FEchoCommand.Parameters[0].Value := I;
FEchoCommand.ExecuteNonQuery;
Result := FEchoCommand.Parameters[1].Value as System.IO.Stream;
end;















TDBXStreamValue Server Method
procedure TTestStreamValue.Swap(I: TDBXStreamValue; J: TDBXStreamValue);
Delphi/DbExpress
procedure TTestStreamValueClient.Swap(var I: TStream; var J: TStream);
begin
if FSwapCommand = nil then
begin
FSwapCommand := FDBXConnection.CreateCommand;
FSwapCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FSwapCommand.Text := 'TTestStreamValue.Swap';
FSwapCommand.Prepare;
end;
if I = nil then
FSwapCommand.Parameters[0].Value.SetNull
else
FSwapCommand.Parameters[0].Value.SetStream(I, FInstanceOwner);
if J = nil then
FSwapCommand.Parameters[1].Value.SetNull
else
FSwapCommand.Parameters[1].Value.SetStream(J, FInstanceOwner);
FSwapCommand.ExecuteUpdate;
if FSwapCommand.Parameters[0].Value.IsNull then
I := nil
else
I := FSwapCommand.Parameters[0].Value.GetStream(FInstanceOwner);
if FSwapCommand.Parameters[1].Value.IsNull then
J := nil
else
J := FSwapCommand.Parameters[1].Value.GetStream(FInstanceOwner);
end;

Delphi Prism/ADO.NET
procedure TTestStreamValueClient.Swap(var I: System.IO.Stream; var J: System.IO.Stream);
begin
if FSwapCommand = nil then
begin
FSwapCommand := FDBXConnection.CreateCommand as TAdoDbxCommand;
FSwapCommand.CommandType := System.Data.CommandType.StoredProcedure;
FSwapCommand.CommandText := 'TTestStreamValue.Swap';
FSwapCommand.Prepare;
end;
if I = nil then
FSwapCommand.Parameters[0].Value := DbNull.Value
else
FSwapCommand.Parameters[0].Value := I;
if J = nil then
FSwapCommand.Parameters[1].Value := DbNull.Value
else
FSwapCommand.Parameters[1].Value := J;
FSwapCommand.ExecuteNonQuery;
if FSwapCommand.Parameters[0].Value = DBNull.Value then
I := nil
else
I := FSwapCommand.Parameters[0].Value as System.IO.Stream;
if FSwapCommand.Parameters[1].Value = DBNull.Value then
J := nil
else
J := FSwapCommand.Parameters[1].Value as System.IO.Stream;
end;

That’s all for now.  A post on table parameter types is coming soon. 

Comments

  • Guest
    Ivan Revelli Saturday, 25 April 2009

    DataSnap is fabulos!!! Prism too, i know that with mono you can build clients for linux too.
    But if it was possible to produce native client for linux... like an .so for apache with delhpi ... i belive in it..

  • Guest
    David Intersimone Sunday, 26 April 2009

    Jim - This is a great series of articles. Is it possible to build client and/or server examples using other languages like Java, PHP, Ruby, and Python? That would be cool!

  • Guest
    Jim Tierney Tuesday, 28 April 2009

    David - If you can, attend Adrian's Delphi Live session named "DataSnap 2009 Client/Server Communication Protocol and Beyond" to hear how DataSnap will support more types of clients.

  • Please login first in order for you to submit comments
  • Page :
  • 1