Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-10

corba interface casting

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Ishenin

Hello, FPC developers' list

I have a code with 2 parent-child corba interfaces and 2 parent-child classes:

Intf1 = interface
...
end;

Intf2 = interface(Intf1)
   ...
   procedure DoSomething;
end;
Class1 = class
   Intf: Intf1;
   function GetIntf: Intf1; virtual;
end;
Class2 = class
   Intf: Intf2;
   function GetIntf: Intf1; override;
end;
function Class2.GetIntf: Intf1;
begin
   Result := Itnf; // this is Intf2
end;
var
   C: Class2;
   I: Intf2;
...
   I := Intf2(C.GetIntf);

Is this ^^^^ a correct interface cast? If not then how to cast one corba interface to another propely?

I'm asking because without -CR the code compiles and with it gives an error Error: Class or COM interface type expected, but got "Intf2"

Best regards,
Paul Ishenin.

Reply by email

Sven Barth
to Paul Ishenin
Paul Ishenin wrote 40 lines
Hello, FPC developers' list I have a code with 2 parent-child corba interfaces and 2 parent-child classes: Intf1 = interface ... end; Intf2 = interface(Intf1) ... procedure DoSomething; end; Class1 = class Intf: Intf1; function GetIntf: Intf1; virtual; end; Class2 = class Intf: Intf2; function GetIntf: Intf1; override; end; function Class2.GetIntf: Intf1; begin Result := Itnf; // this is Intf2 end; var C: Class2; I: Intf2; ... I := Intf2(C.GetIntf); Is this ^^^^ a correct interface cast? If not then how to cast one corba interface to another propely? I'm asking because without -CR the code compiles and with it gives an error Error: Class or COM interface type expected, but got "Intf2"

Did you try with "C.GetIntf as Intf2"? That should be the correct way to do this...

Regards,
Sven

Reply by email

Paul Ishenin
to Sven Barth
Sven Barth wrote 10 lines
> I := Intf2(C.GetIntf); > > Is this ^^^^ a correct interface cast? If not then how to cast one corba > interface to another propely? > > I'm asking because without -CR the code compiles and with it gives an > error Error: Class or COM interface type expected, but got "Intf2" Did you try with "C.GetIntf as Intf2"? That should be the correct way to do this...

Yes, but it does not work.

Best regards,
Paul Ishenin

Reply by email

JC Chu
to Paul Ishenin: Hello, FPC developers' list I have a code with 2 parent-child corba interfaces and 2…

With CORBA interfaces I don’t think an ancestor interface can be cast to a derived interface unless one recover from the interface variable alone the implementor’s class instance, which does not seem possible outside of the implementor itself.

Reference: http://wiki.freepascal.org/Compiler_generated_data_and_data_structures.

(Sorry for the duplicate, Paul, the previous reply was not sent to the list.)

Best regards, JC Chu

Reply by email