我将接口的引用从 Visio 加载项传递给 MyCOMServer(Delphi 中的接口编组必须将接口作为指针传递给 MyCOMServer 的内部方法。我尝试将接口作为接口的指针传递给内部方法,但是当我尝试调用时返回转换后接口的方法我得到异常。简单的例子(第一个块执行没有错误,但在第二个块我在寻址到 IVApplication 接口的属性后得到异常):
procedure TMyCOMServer.test(const Interface_:IDispatch); stdcall;
var
IMy:_IMyInterface;
V: Variant;
Str: String;
I: integer;
Vis: IVApplication;
begin
......
{First code Block}
Self.QuaryInterface(_IMyInterface,IMy);
str := IMy.ApplicationName;
V := Integer(IMy);
i := V;
Pointer(IMy) := Pointer(i);
str := IMy.SomeProperty; // normal completion
{Second code Block}
str := (Interface_ as IVApplication).Path;
V := Interface_;
I := V;
Pointer(Vis) := Pointer(i);
str := Vis.Path; // 'access violation at 0x76358e29: read of address 0xfeeefeee'
end;
为什么我不能这样做?