Free Pascal 多接口问题
这可能会很困难——我在一个对象上使用多个 CORBA 接口,所以它看起来像这样:
TBaseObject = class(TSuperBaseObject, IInterfaceA)
function Afunction; // implemented from IInterfaceA
end;
TOtherObject = class(TBaseObject, IInterfaceB);
function Bfunction; // implemented from IInterfaceB
end;
现在我有一个接受变体的函数,如果该变体是一个对象,它假设该对象是一个IInterfaceA 对象:
case var.vtype of
...
vtObject : begin
Something := (var.vObject as IInterfaceA).AFunction; (1)
end;
end;
现在,一旦我运行该代码,并将 TOtherObject 传递给函数,第 (1) 行中的 BFunction 就会使用强制参数进行调用!
我做错了什么还是编译器中的错误?另外,有什么明智的方法可以在不改变类结构的情况下规避这个问题吗?
如果有人想尝试,请参阅 EAccessViolation 的完整代码 - http://pastebin.com/D7sDpDHx
This may prove difficult -- I'm using multiple CORBA interfaces on an object, so it looks somehow like this:
TBaseObject = class(TSuperBaseObject, IInterfaceA)
function Afunction; // implemented from IInterfaceA
end;
TOtherObject = class(TBaseObject, IInterfaceB);
function Bfunction; // implemented from IInterfaceB
end;
Now I have a function that takes a variant, and in case that variant is an object, it assumes that object to be a IInterfaceA object:
case var.vtype of
...
vtObject : begin
Something := (var.vObject as IInterfaceA).AFunction; (1)
end;
end;
Now once I run that code, and pass a TOtherObject to the function, in line (1) BFunction gets called with forced parameters!
Am I doing something wrong or is it a bug in the compiler? Also, any sane way to circumvent that without changing the class structure?
Full code for a EAccessViolation if anyone wants to try - http://pastebin.com/D7sDpDHx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将此作为错误报告给 FPC bugtracker - http://bugs.freepascal.org/view .php?id=20076
原来FPC内部不识别CORBA接口。要解决这个问题,需要自己识别它们:
然后
as
关键字就起作用了。Reported this as a bug to the FPC bugtracker - http://bugs.freepascal.org/view.php?id=20076
It turned out that FPC doesn't identify CORBA interfaces internally. To solve the problem one needs to identify them by himself:
Then the
as
keyword will work.不确定 FreePascal,但在 Delphi 中,您将使用supports函数来查询接口。
Not sure about FreePascal, but in Delphi you would use the supports function to query the interface.