Problema de interfaces múltiples de Free Pascal

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

TOtherObject = class(TBaseObject, IInterfaceB);  
  function Bfunction; // implemented from IInterfaceB

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)

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 -

preguntado el 27 de agosto de 11 a las 23:08

2 Respuestas

Reported this as a bug to the FPC bugtracker -

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;

Entonces el as keyword will work.

Respondido el 02 de junio de 16 a las 18:06

Not sure about FreePascal, but in Delphi you would use the supports function to query the interface.

    IntfA : IInterfaceA;
    IntfB : IInterfaceB;
 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;

Respondido 28 ago 11, 10:08

+1: FPC doesn't seem to have the supports keyword, it also uses CORBA style interfaces, not COM, but the answer put me on the right track of searching. - Kornel Kisielewicz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.