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
preguntado el 27 de agosto de 11 a las 23:08
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:
type IInterfaceA = interface['interface_a'] function AFunction; end;
as keyword will work.
Not sure about FreePascal, but in Delphi you would use the supports function to query the interface.
var IntfA : IInterfaceA; IntfB : IInterfaceB; begin case var.vtype of ... vtObject : begin if supports(var.vObject,IInterfaceA,IntfA) then Something := IntfA.AFunction else if supports(var.vObject,IInterfaceB,IntfB) then Something := IntfB.BFunction; end; end; end;