我试图在来自 ActiveX 库的回调中访问 OleVariant。
以下是事件处理程序在 TLB 中的定义:
procedure(ASender: TObject; var structQSnap: {??structVTIQSnap}OleVariant) of object;
这是 TLB 中 structVTIQSnap 的定义:
structVTIQSnap = packed record
bstrSymbol: WideString;
bstrListingExch: WideString;
bstrLastExch: WideString;
fLastPrice: Double;
nLastSize: Integer;
bstrBbo: WideString;
bstrBidExch: WideString;
fBidPrice: Double;
nBidSize: Integer;
bstrAskExch: WideString;
fAskPrice: Double;
nAskSize: Integer;
fHighPrice: Double;
fLowPrice: Double;
fOpenPrice: Double;
fClosePrice: Double;
nCumVolume: Integer;
bstrTradeCondition: WideString;
nQuoteCondition: Integer;
bstrCompanyName: WideString;
f52WeekHigh: Double;
f52WeekLow: Double;
fEps: Double;
nSharesOutstanding: Integer;
nSpCode: Integer;
fBeta: Double;
bstrExDivDate: WideString;
nDivFreq: Integer;
fDivAmt: Double;
nAvgVolume: Integer;
bstrCusip: WideString;
fVwap: Double;
bstrUpdateTime: WideString;
bstrExch: WideString;
nSharesPerContract: Integer;
end;
它编译得很好,但是每次我尝试访问 bstrSymbol 时,我都会得到一个“无效的变体操作”:
procedure TForm1.HandleVTIQuoteSnap(ASender: TObject; var structQSnap: OleVariant);
var
symbol: WideString;
begin
symbol := structQSnap.bstrSymbol; // this line causes the exception
end;
如何在 Delphi 中访问 structQSnap 及其属性?
在 C# 中,此函数适用于事件处理程序:
void vtiQ_OnVTIQSnap(ref vtiLib.structVTIQSnap structQSnap)
{
MessageBox.Show("Got qsnap for " + structQuoteSnap.bstrSymbol);
}
有任何想法吗?