[fpc-devel] {$Interfaces Corba} and TInterfacedObject

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Nov 29 12:42:42 CET 2007


On 29/11/2007, Thorsten Engler <thorsten.engler at gmx.net> wrote:
>
> You can assign from an object to a (non-COM) interface variable:
>
> var
>   Obj: TSomeObject;
>   Intf: ISomeInterface;
> begin
>   ...
>   Intf := Obj as ISomeInterface;


[  I can't find the message I just sent in my Outbox, so here it is again.  ]

I tried what you said and got a error at runtime.

graemeg at graemeg:command_interface$ ./test
An unhandled exception occurred at $080553C1 :
EInvalidCast : Invalid type cast


and the code...

var
  cmd: ICommand;
  holder: ICommandHolder;
  ins: TAddCommand;
begin
  ins := TAddCommand.Create(memName1);
  cmd := ins as ICommand;
  if Assigned(cmd) then
  begin
    writeln('It worked');
    cmd.Execute;
  end;
  ins.Free;
end;


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list