关于 datasnap Stream的英文博客能容
转载:http://blogs.embarcadero.com/jimtierney/2009/04/06/31461/
DataSnap Server Method Stream Parameters
This is a continuation of my posts on DataSnap server method parameters and return types. This post is about TStream and TDBXStreamValue. The sample client and server projects that go with this post can be downloaded here: http://cc.embarcadero.com/item/26854
See my earlier posts on “Basic” and “Basic DBXValue” types. I’ve yet to post about TDBXConnection, TDBXConnectionValue, TDBXReader, TParams, and TDataSet. However, TDataSet is demonstrated in the sample projects.
| Basic | Basic DBXValue | Collection | Connection | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
The following table summarizes differences between TStream and TDBXStreamValue types:
| Supports null values | Declaration | Accessing Values | Proxy generator | ||||
|---|---|---|---|---|---|---|---|
| Default parameter direction | Other parameter directions | function result type | Get | Set | |||
| TStream | No |
in |
in/out: usevar keyword out: use outkeyword |
Yes |
lhs := AParameter | AParameter := rhs |
Yes |
| TDBXStreamValue |
Yes |
in/out |
None |
No |
AParameter.IsNull lhs:=AParameter.GetStream(InstanceOwner) | AParameter.SetNull AParameter.SetStream(rhs, InstanceOwner) |
No |
Supports null values
The TDBXStreamValue type has an IsNull property and a SetNull method. Use this type instead of TStream a parameter value can be null/nil, in some cases.
Declaration
The var and out keywords can’t be used to specify the parameter direction of a TDBXStreamValue parameter. The direction is always in/out. A TDBXStreamValue type can’t be used as a function result.
Proxy Generator
The RAD Studio 2007 client proxy generator does not work properly for server methods with TDBXStreamValue parameters. So you will need to hand code the client code or correct the generated proxy. The sample client has hand corrected proxy methods that look like this.
function TTestStreamValueClient.Echo(var I: TStream): TStream;
begin
if FEchoCommand = nil then
begin
FEchoCommand := FDBXConnection.CreateCommand;
FEchoCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FEchoCommand.Text := 'TTestStreamValue.Echo';
FEchoCommand.Prepare;
end;
if I = nil then
FEchoCommand.Parameters[0].Value.SetNull
else
FEchoCommand.Parameters[0].Value.SetStream(I, FInstanceOwner);
FEchoCommand.ExecuteUpdate;
if FEchoCommand.Parameters[0].Value.IsNull then
I := nil
else
I := FEchoCommand.Parameters[0].Value.GetStream(FInstanceOwner);
Result := FEchoCommand.Parameters[1].Value.GetStream(FInstanceOwner);
end;
This client method works with a server method declared as follows:
function Echo(I: TDBXStreamValue): TStream;
Calling a server method with a TDBXStreamValue parameter is the same as calling a server method with an TStream parameter, except that you can use SetNull and IsNull methods to work with null values.
For example, compare the following server method declaration and client method implementation to the previous example:
function Echo(I: TStream): TStream;
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;
Accessing Values
The GetStream and SetStream methods have an InstanceOwner parameter. Passing True indicates that DBX owns the stream and will free it. Passing False indicates that the caller owns the stream. To control how the generated proxy classes call SetStream and GetStream, there is an AInstanceOwner parameter on the proxy class constructor:
constructor TTestStreamClient.Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean);
The other constructor is equivalent to passing AInstanceOwner as True.
constructor TTestStreamClient.Create(ADBXConnection: TDBXConnection);
Sample Client And Server Applications
The sample server has a few simple server methods for passing values (including null).
{$METHODINFO ON}
TTestCollection = class(TComponent)
strict protected
procedure LogMessage(const AMessage: string);
public
// Server method to get the parameter type names
procedure GetTypeNames(I: T; ADeclaredName, AActualName: TDBXStringValue);
end;
{$METHODINFO OFF}
TTestStream = class(TTestCollection)
public
function Echo(I: TStream): TStream;
procedure Copy(I: TStream; out J: TStream);
procedure Swap(var I: TStream; var J: TStream);
end;
TTestStreamValue = class(TTestCollection)
public
function Echo(I: TDBXStreamValue): TStream;
procedure Copy(I: TDBXStreamValue; J: TDBXStreamValue);
procedure Swap(I: TDBXStreamValue; J: TDBXStreamValue);
function IsNull(I: TDBXStreamValue): Boolean;
procedure SetNull(I: TDBXStreamValue);
end;
The sample client tests the server methods by calling them with sample values and verifying the results (e.g; comparing streams). TMemoryStream is used to pass short streams and TFileStream to pass long streams. Here is a screen shot of the running server and client:

The following table shows the parameter types and return types demonstrated in the sample client and server:
| Type | Direction | |||
|---|---|---|---|---|
| (default) | var | out | Result | |
| TDBXStreamValue | X (in/out) | |||
| TStream | X (in) | X | X | X |
Stream Usage
Check “Log Stream Usage” to show TStream sizes, type names, creates, destroys, and reads. The results from 4 different test cases are displayed after “Call Server Methods” is clicked.
The screen shot below shows the result from a test case with longer streams. I’ve added highlighting to illustrate these points:
- When the server reads a longer stream passed from the client, round trips are made to the client. This makes it possible to send very large streams to the server without consuming lots of memory.
- When the client reads a longer stream passed from the server, round trips are made to the server. This makes it possible to return very large streams to the client without consuming lots of memory.
- The TStream objects that represent longer client and server streams have a Size of –1, meaning the size is unknown. Rely on the return value of TStream.Read to detect the end of the stream. Also note that some DBX streams such as TDBXStreamReaderStream do not fully support Seek.

That’s all for now.
附件:( http://cc.embarcadero.com/item/26854 链接的文件)
关于 datasnap Stream的英文博客能容的更多相关文章
- 30大最有影响力的Web设计与开发英文博客
1stwebdesigner的创始人Dainis Graveris挑选出30个高质量和具有影响力的Web设计与前端技术博客,其中很多我们都耳熟能详.但这么完整的列表,还是值得收藏的.另外,你大概不会了 ...
- 值得关注的 10 个 Python 英文博客
英文原文:http://pythontips.com/2013/07/31/10-python-blogs-worth-following/ 中文翻译参考: http://python.jobbole ...
- 本文可能是国内第一篇介绍C/4HANA Foundation的中文博客
SAP C/4HANA从去年发布已经过去了一年多的时间,C/4HANA的从业者,对于这五朵云里包含的产品集,想必都有了一些了解. Jerry注意到,SAP C/4HANA Foundation这个概念 ...
- 1、了解计算机与操作系统发展阶段 2、选择一个具体的操作系统,结合计算机与操作系统的发展阶段,详细了解其渊源、发展过程、趋势,整理成简洁美观的图文博客发布。 Windows Mac os x Unix Linux Android 等。
1.了解计算机与操作系统发展阶段 操作系统并不是与计算机硬件一起诞生的,它是在人们使用计算机的过程中,为了满足两大需求:提高资源利用率.增强计算机系统性能,伴随着计算机技术本身及其应用的日益发展,而逐 ...
- 【相关网站 - 02】- Java 好文博客
一.源码分析博客 还有这种操作?浅析为什么要看源码 你觉得什么才是 Java 的基础知识? 1. JDK 2. Mybatis 3. Spring 4. Sring Boot 5. Spring Cl ...
- CasperJS API中文博客链接
http://www.cnblogs.com/reach296/tag/Casperjs/
- Windows Azure中文博客 Windows Azure入门教学系列 (一): 创建第一个WebRole程序
http://blogs.msdn.com/b/azchina/ 本文转自:http://blogs.msdn.com/b/azchina/archive/2010/02/09/windows-azu ...
- 七步,搭建基于Windows平台完美Jekyll博客环境
最近,基于Jekyll新搭建了自己英文博客.整个过程搜索了不少资料,也尝试和过滤了不少工具和插件,最后的效果还是不错的.这里总结一下主要的七个步骤,感兴趣的朋友可以参考一下: 第一步,安装Ruby开发 ...
- 对写博客的n种思考
喜欢才能坚持 开始写博客的原因非常功利,功利到不好意思说. 反正你们也懂的,就那么几种. 问题是,如果心态一直这么功利,而写博客的前期回报几乎为零,情绪会变得沮丧,不知如何继续. 不过后来想想,其实做 ...
随机推荐
- [工具类]DataTable与泛型集合List互转
写在前面 工作中经常遇到datatable与list,对于datatable而言操作起来不太方便.所以有的时候还是非常希望通过泛型集合来进行操作的.所以这里就封装了一个扩展类.也方便使用. 类 方法中 ...
- JavaScript、CSS、JSP 实现用户注册页面与信息校验
参考:http://blog.csdn.net/fightfaith/article/details/50277337 需求:实现用户注册页面并作出逻辑校验.要求: (1)完成注册页面样式如下: (2 ...
- ansible 配置运行环境
P34 2.3.1 配置ansible的环境 ansible的配置文件是以ini格式存储配置数据的,在ansible中几乎所有的配置都可以通过playbook或者环境变量来重新赋值 运行ansible ...
- Java基础-字面值
在Java源代码中,字面值用于表示固定的值(fixed value).数值型的字面值是最常见的,字符串字面值可以算是一种,当然也可以把特殊的null当做字面值.字面值大体上可以分为整型字面值.浮点字面 ...
- Freemarker 之 Java静态化 实例一
Freemarker是一种强大的web端模板技术,在当前Web开发中,SEO和客户端浏览速度尤为重要,其中将网页静态化是一个很好的解决方案.下面介绍Java中web开发结合Freemarker来实现静 ...
- mysql库大小
1.进入information_schema 数据库(存放了其他的数据库的信息) use information_schema; 2.查询所有数据的大小: select concat(round(su ...
- 7.Android之评分条RatingBar和拖动条SeekBar学习
评分条RatingBar和拖动条SeekBar很常见,今天来学习下. (1)RatingBar评分条 如图: <RelativeLayout xmlns:android="http:/ ...
- ORACLE创建表空间、创建用户、更改用户默认表空间以及授权、查看权限
Oracle创建用户.表空间.导入导出....命令 //创建临时表空间 create temporary tablespace ext_temptempfile 'D:\oracle\product\ ...
- BZOJ-1800 飞行棋 数学+乱搞
这道题感觉就是乱搞,O(n^4)都毫无问题 1800: [Ahoi2009]fly 飞行棋 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1172 So ...
- spring 第一篇(1-1):让java开发变得更简单(下)转
spring 第一篇(1-1):让java开发变得更简单(下) 这个波主虽然只发了几篇,但是写的很好 上面一篇文章写的很好,其中提及到了Spring的jdbcTemplate,templet方式我之前 ...