[fpc-pascal] casting interfaces and objects

Graeme Geldenhuys graemeg.lists at gmail.com
Sun May 18 23:41:45 CEST 2008

2008/5/18 Marc Santhoff <M.Santhoff at t-online.de>:
> Since the compiler dod not warn about using the "as" operator I assume
> it is safe? Like this:
> procedure TObservable.DeRegister( obsv: IObserver );
> var
>        i: integer;
> begin
>        if (fObservers.count<=0) then exit;
>        for i:=0 to fObservers.count-1 do begin
>                if ((fObservers[i] as IObserver)=obsv) then begin

I'm not a big Interfaces expert, but as for as I know using 'as' like
that with Interfaces actually translates to a QueryInterface() call
internally, which is why it is allowed.  I vaguely remember as issue
between CORBA and COM interfaces and the 'as' call, because CORBA
interfaces do not have a QueryInterface() implementation. Well,
something like that... :-)

 - Graeme -

fpGUI - a cross-platform Free Pascal GUI toolkit

More information about the fpc-pascal mailing list