用接口
给你给例子,把他改一下就可以了。
服务器端:
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;
如果需要反向传数据就反过来就行了!