9
votes
Vote UpVote

Casting an Interface to a Class, the efficient way

DelphiTools – Delphi 2010 added support for the “as” to cast an interface reference to its implementation class. Cast interface as class type IFoo = interface ... end; TFoo = class (TInterfacedObject, IFoo) ... end; ... var intf : IFoo; var foo : TFoo; ... intf := TFoo.Create; ... foo := intf as TFoo; // get back the implementation class However, if “as” can be convenient in certain scenarios, it’s alas not implemented very efficiently: the compiler and RTL go through several hoops to perform it (cf. this article by Arnaud Bouchez). One of those hoops f.i. gets slower the ...
Favorite? Off-Topic? Eric @ 2012-07-04 15:09

Statistics

Visits: 826
Votes: 9
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
Ericc
François
Jeroen Pluimers
Jørn E. Angeltveit
knight_killer
Ravaut123
Yogi Yang
Zzzzz
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

 
Please login or register to use this functionality.
(click on this box to dismiss)