Sign in Join

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

Mailing lists / fpc-pascal / 2011-12

IInterface type value and the "as" keyword

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Honza

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.

Marco van de Voort
to Honza

In our previous episode, Honza said:

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).

Early that year 2.5.1 was trunk yes. That same code is now the future fixes branch for 2.6, for which a RC1 is already available.

Now I'm trying to make that code work with current stable (AFAICS that's 2.4.4)

Correct, but it is relatively short before the 2.6.0 release, with a first RC1 already available. Since 2.6.0 might arrive this year still (or in the first week of the next), I suggest your focus your attention there, and forget about 2.4.4.

Show quoted text 6 lines
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.

I assume it is bugfixed in 2.5+, which never made it back to the 2.4 series.

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.

It doesnt seem to be one of the major differences, so it is not a stupid question.

(major ones I mean documented ones like:
http://wiki.freepascal.org/User_Changes_2.6.0#IInterface.QueryInterface.2C_._AddRef_and_._Release_definitions_have_been_changed )

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

As said I think it is simply one of those minor bugfix related differences between the 2.4 and 2.6 (and +) series.

Honza
to Marco van de Voort

2011/12/11 Marco van de Voort :

Show quoted text 8 lines
In our previous episode, Honza said: > Now I'm trying to make that code work with > current stable (AFAICS that's 2.4.4) Correct, but it is relatively short before the 2.6.0 release, with a first RC1 already available. Since 2.6.0 might arrive this year still (or in the first week of the next), I suggest your focus your attention there, and forget about 2.4.4.

Good suggestion, done exactly that.

Show quoted text 8 lines
> 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. I assume it is bugfixed in 2.5+, which never made it back to the 2.4 series.

Yes, after switching to 2.6.0 the problem disappeared, thank you very much!

Thanks to your help (and some hours of hacking), I'm now here: ----
$ ./helib_test -a -p --format=plain
...
Number of run tests: 701
Number of errors: 0
Number of failures: 0

Heap dump by heaptrc unit
5844426 memory blocks allocated : 252487390/286727568 5844426 memory blocks freed : 252487390/286727568 0 unfreed memory blocks : 0
True heap size : 294912
True free heap : 294912
$
----

;-)

Thanks again!

Best regards,

-bflm

PS: helib/heContnrs release-0.4, RC1 for FPC 2.6.0 (tested with svn rev 19814), tar download available here:
http://code.google.com/p/fprb/downloads/detail?name=release-0.4.tar.gz Feedback/issue reports/volunteers to test on other platforms/architectures/... welcome. (I can easily run tests only on 64bit Ubuntu 10.10.)