5
votes
Vote UpVote

An ugly alternative to interface to object casting

Entropy Overload – I was answering a question on Stack Overflow, but the user didn't have the latest version of Delphi. My answer included converting an interface to an object instance, which is made possible with the as cast on interfaces in recent Delphi versions. But there is another way of doing it, exploiting the regularity Delphi interface vtable implementations: {$apptype console} function Intf2Obj(x: IInterface): TObject; type TStub = array[0..3] of Byte; const // ADD [ESP+$04], imm8; [ESP+$04] in stdcall is Self argument, after return address add_esp_04_imm8: TStub = ($83, $44, $24, $04); // ...
Favorite? Off-Topic? Barry Kelly @ 2011-03-01 16:27

Statistics

Visits: 1083
Votes: 5
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Francis Ruiz
François
jamiei
JC Chu
TOndrej
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)