我有一個類TRate
降序從IDispatch
和TAutoObject
傳遞對象作爲OleVariant
Type
IRate = interface(IDispatch)
['{60B5A5D1-5BA9-4D28-BBF9-DD5BE2B83ED2}']
function Get_Minimum: Double; safecall;
procedure Set_Minimum(Value: Double); safecall;
function Get_Maximum: Double; safecall;
procedure Set_Maximum(Value: Double); safecall;
property Minimum: Double read Get_Minimum write Set_Minimum;
property Maximum: Double read Get_Maximum write Set_Maximum;
end;
TRate = class(TAutoObject, IRate)
protected
function Get_Maximum: Double; safecall;
function Get_Minimum: Double; safecall;
procedure Set_Maximum(Value: Double); safecall;
procedure Set_Minimum(Value: Double); safecall;
public
fMaximum,fMinimum:double;
destructor Destroy; override;
end;
//INSIDE mscorlib_tlb.pas
// *********************************************************************//
// Interface : IEnumerator
// Indicateurs : (4416) Dual OleAutomation Dispatchable
// GUID : {496B0ABF-CDEE-11D3-88E8-00902754C43A}
// *********************************************************************//
IEnumerator = interface(IDispatch)
['{496B0ABF-CDEE-11D3-88E8-00902754C43A}']
function MoveNext: WordBool; safecall;
function Get_Current: OleVariant; safecall;
procedure Reset; safecall;
property Current: OleVariant read Get_Current;
end;
TRateEnum = class(TAutoObject, IEnumerator)
protected
function Get_Current: OleVariant; safecall;
function MoveNext: WordBool; safecall;
procedure Reset; safecall;
public
fAxe,fCount,fIndex:integer;
end;
我有TRate
類型的對象的下一個g_Rate
陣列。我必須通過IEnumerator
訪問g_Rate
成員。在IEnumerator
的非標準功能Get_Current
,看起來像(返回OleVariant
):
Type
g_Rate:Array [0..2,0..2] of TRate;
end
function TRateEnum.Get_Current: OleVariant;
begin
result:= g_Rate[i,j];
end;
我得到一個編譯錯誤,「類型missmatch,Olevariant TRate」,我怎麼能避免這個問題? Regards
您是否需要將TRate轉換爲IRate。你爲什麼不顯示g_Rate的聲明? [mcve]會有所幫助。知道你正在做什麼類型的COM可能會有用。 –
你能告訴我們你是如何聲明TRateEnum的嗎?這裏有一個很好的例子來說明如何在這裏定義枚舉器:http://stackoverflow.com/questions/32416017/pass-an-object-as-olevariant – uri2x
我已經找到了一個解決方案,答案是David.'function TRateEnum.Get_Current :OleVariant; 開始 結果:= g_Rate [i,j]作爲IRate; end;',但我不知道它爲什麼工作。我對使用接口不太熟悉。我學習,我學習。 – michastro