三层结构中怎么传递 Record 类型参数???(150分)

  • 主题发起人 主题发起人 xeen
  • 开始时间 开始时间
X

xeen

Unregistered / Unconfirmed
GUEST, unregistred user!
当Record 类型中包含[red]String[/red] 类型成员的时候,
用Variant打包的方式不行,别告诉我用Move函数
或者Stream类型操作,我试过了不行.
 
把String 类型编为string[length]形式的声明,
例如以前是
vvvv:string;------->vvvv:string[15];
 
字符串类型必须要确定长度.
或者,可以在Type Library Editor中增加一个记录类型,用来与客户端程序传递记录类型的
数据.
 
可以在Type Library Editor中增加一个记录类型,用来与客户端程序传递记录类型的
数据.
-----------------------------------------------------------------------
可惜我要使用Dispatch call 方式,不能用这种数据类型.
 
procedure TPassOther.GetArray(var VData: OleVariant);
var
IntArray: array[1..10] of Integer;
I: Integer;
PData: PByteArray;
begin
{ Put some numbers in the array. }
for I := 1 to 10do
IntArray := I;
{ Load the integer array into the variant array. }
LoadVariantArray(@IntArray, SizeOf(IntArray), VData);
end;

procedure TPassOther.LoadVariantArray(PData: Pointer;
NumBytes: Integer;
var VData: OleVariant);
var
PVData: PByteArray;
begin
{ Create the variant array of bytes. Set the upper bound
to the size of the array, minus one, because the array
is zero-based. }
VData := VarArrayCreate([0, NumBytes - 1], varByte);
{ Lock the variant array for faster access. then
copy the
array to the variant array, and unlock the variant
array. }
PVData := VarArrayLock(Vdata);
try
{ Move the bytes at the location in memory that PData
points to into the location in memory that PVData
points to. PData points to the integer array and
PVData points to the variant array of bytes. }
Move(PData^, PVData^, NumBytes);
finally
VarArrayUnlock(VData);
end;
// try
end;


=======================================================================


procedure TMainForm.UnloadVariantArray(
var VData: OleVariant;
PData: Pointer;
NumBytes: Integer);
var
PVData: PByteArray;
begin
{ Lock the variant array, copy the data to the array, and
unlock the variant array. }
PVData := VarArrayLock(VData);
try
{ Move the data in memory that PVData points to (the
variant array data), to the location in memory that
PData points to (the integer array). }
Move(PVData^, PData^, NumBytes);
finally
VarArrayUnlock(VData);
end;
// try
end;
 
多人接受答案了。
 
后退
顶部