应用服务器和客户端如何传递流?(100分)

  • 主题发起人 主题发起人 陕西太守
  • 开始时间 开始时间

陕西太守

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要在应用服务器和客户端间传递诸如文件流等,但又不想用网络组件或数据库技术,采用怎样的转换才能实现呢?
 
帮你顶!!!
 
varbyte数组
procedure VariantToStream(const Data: OleVariant;
Stream: TMemoryStream);
var
p: Pointer;
begin
p := VarArrayLock(Data);
try
Stream.Write(p^, VarArrayHighBound(Data,1) + 1);

finally
VarArrayUnlock(Data);
end;
end;

function StreamToVariant(Stream: TStream): OleVariant;
var
p: Pointer;
begin

Result := VarArrayCreate([0, Stream.Size - 1], varByte);
p := VarArrayLock(Result);

try
Stream.Position := 0;

Stream.Read(p^, Stream.Size);

finally
VarArrayUnlock(Result);

end;

end;
 
用接口
给你给例子,把他改一下就可以了。
服务器端:
TMyRecord = record
no: Integer;
name: string;//类型有错string[255]
address: string;
end;

procedure VariantToStream(const Data: OleVariant;
Stream: TStream);
var
p: Pointer;
begin
p := VarArrayLock(Data);
try
Stream.Write(p^, VarArrayHighBound(Data,1) + 1);
//assuming low bound
= 0
finally
VarArrayUnlock(Data);
end;
end;

procedure TcoServerObj.GetInfo(vDatas: OleVariant);
var
MyStream: TMemoryStream;
vInfo: TMyRecord;
s: String;
begin
MyStream := TMemoryStream.Create;
VariantToStream(vDatas,MyStream);
MyStream.Seek(0,soFrombegin
ning);
MyStream.Read(vInfo,sizeof(TMyRecord));
MyStream.Free;
s := vInfo.name;
........处理你的数据
end;

************************************************
客户端:
TMyRecord = record
no: Integer;
name: string
address: string;
end;

function StreamToVariant(Stream: TStream): OleVariant;
var
p: Pointer;
begin
Result := VarArrayCreate([0, Stream.Size - 1], varByte);
p := VarArrayLock(Result);
try
Stream.Position := 0;
//start from begin
ning of stream
Stream.Read(p^, Stream.Size);
finally
VarArrayUnlock(Result);
end;
end;

procedure TFrom1.BitBtn1Click(Sender: TObject);
var
ServerObj: IServerObj;
vInfo: TMyRecord;
MyStream: TMemoryStream;
begin
ServerObj := CoServerObj.CreateRemote('FreeSky');
//创建过程参数
MyStream := TMemoryStream.Create;
MyStream.Write(vInfo,sizeof(TServerInfo));
MyStream.Seek(0,soFrombegin
ning);
ServerObj.GetInfo(StreamToVariant(MyStream));//把流转成OleVariant当参数传

MyStream.Free;
end;

如果需要反向传数据就反过来就行了!
 
陕西太守搞定没有,还不行,我发例子给你
 
to zqs10597249:
方便的话给我发份学习。谢谢。
 
后退
顶部