从Delphi访问包含VT_RECORD的VT_ARRAY的OleVariant [英] Accessing OleVariant containing VT_ARRAY of VT_RECORD from Delphi
本文介绍了从Delphi访问包含VT_RECORD的VT_ARRAY的OleVariant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Delphi,我需要访问一个在数组中包含一个或多个记录的OleVariant.
Using Delp I need to access a OleVariant containing one or more records in an array.
我调用的方法返回一个VT_RECORD的VT_ARRAY,并且记录本身定义为:
The method I call returns a VT_ARRAY of VT_RECORD, and the records themselves are defined as:
struct StreamTimeInfo {
unsigned int PID;
LONGLONG PTS;
LONGLONG TimeStamp;
};
我的代码是这样的:
procedure Test;
type
TStreamInfo = record
PID: Cardinal;
PTS: Int64;
TimeStamp: Int64;
end;
var
Value: OleVariant
StreamTime: TStreamInfo;
begin
GetValue(Value); // Value holds a VT_ARRAY of VT_RECORD
// How should I access the array of records in Delphi?
// I've tried this to get to the first element:
StreamTime := TStreamInfo(TVarData(Value).VPointer^);
end;
我不明白如何从Delphi中访问记录.
I do not understand how to access the records from Delphi.
非常感谢任何输入.
推荐答案
我以前从未做过,但是我认为这应该可行.
I've never done this before, but I think this should work.
type
TStreamInfoArray = array [0..MaxArrayCount-1] of TStreamInfo;
PStreamInfoArray = ^TStreamInfoArray;
var
Value: Variant;
p: PStreamInfoArray;
StreamInfo: TStreamInfo;
begin
GetValue(Value);
p := PStreamInfoArray(VarArrayLock(Value));
try
StreamInfo := p^[Index];
finally
VarArrayUnlock(Value);
end;
end;
这篇关于从Delphi访问包含VT_RECORD的VT_ARRAY的OleVariant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文