[fpc-pascal] IInterface type value and the "as" keyword

Honza befelemepeseveze at gmail.com
Sun Dec 11 12:02:17 CET 2011


Hi list,

after a long pause I'm trying to revive some code which I didn't touch
as long as early this year. At that time it compiled OK with trunk FPC
(I believe version 2.5.1). Now I'm trying to make that code work with
current stable (AFAICS that's 2.4.4). Everything went smooth until
compiler stumbled upon:

function TheInterfaceListTest.Value(const It: IInterface): Integer;
begin
  Result := (It as TInterfacedTracedObject).ID; // <-- line 238
end;

with the error: "hecontnrs_list_test.pas(238,17) Error: class type
expected, but got "IUnknown".

FYI: TInterfacedTracedObject interface is:

  TInterfacedTracedObject = class(TInterfacedObject)
  private
    FID: Integer;
    FTracer: TBits;
  public
    constructor Create(const ATracer: TBits; const AID: Integer);
    destructor Destroy; override;
    property ID: Integer read FID;
    property Tracer: TBits read FTracer;
  end;

I suppose something has changed with the FPC interfaces and/or using
the "as" keyword in the above construct. Of course I searched e.g. the
"changes" wiki pages 2.4.0->2.4.2->2.4.4(and even ->2.6.0), but I
failed to find anything related, the same result for the mailing lists
and general googling attempts. And of course I tried every single
change to the code I could imagine may work.

That said, I'm sure it's my fault to find the info or it's my fault in
some other way - me being blind to see something obviously wrong with
the code in the snippet, though I'm sure it used to compile w/o
problem before.

Can please someone enlighten me? Thanks in advance, sorry for being dumb ;-)

Best regards,

-bflm

PS: Actually I found some recent discussions about FPC interfaces, but
if I understood them correctly, no one of them seemed to me like an
explanation for my problem.



More information about the fpc-pascal mailing list