你搞错了!
服务端和客户端都要有你的结构说明。
服务端提供的方法参数为Olevariant类型。
举个例子
服务器端:
TMyRecord = record
no: Integer;
name: string
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;
如果需要反向传数据就反过来就行了!