[fpc-pascal] Dynamic messaging in Delphi
Graeme Geldenhuys
graemeg.lists at gmail.com
Thu Jul 26 10:32:38 CEST 2012
On 24 July 2012 15:13, Ryan Joseph <ryan at thealchemistguild.com> wrote:
> procedure InvokeDelegate (delegate: TObject);
> var
> intfDelegate: IMyInterface;
> begin
> ERROR ====> intfDelegate := IMyInterface(delegate);
> intfDelegate.DoThis(1);
> end;
You could also try the Supports() method. eg:
if Supports(delegate, IMyInterface, intfDelegate) then
intfDelegate.DoThis(1);
>
> {$mode delphi}
> {$interfaces corba}
>
> program Main;
> uses
> MyInterface;
>
> type
> TMyDelegate = class (TInterfacedObject, IMyDelegate)
> procedure DoThis (value: integer);
> end;
By the way, as far as I know TInterfacedObject is a COM Interface
class only. You are telling the compiler that you want to use CORBA
style interfaces, which don't support IUnknown, thus you shouldn't
(can't) use TInterfaceObject which implements IUnknown.
Change that class definition to something like the following if you
are using CORBA interfaces.
TMyDelegate = class(TObject, MyDelegate)
...
end;
And that should work correctly with CORBA style interfaces (which
don't have reference counting built-in).
--
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net
More information about the fpc-pascal
mailing list