- //=== Interface information ==================================================
- function GetImplementorOfInterface(const I: IInterface): TObject;
- { TODO -cDOC : Original code by Hallvard Vassbotn }
- { TODO -cTesting : Check the implemetation for any further version of compiler }
- const
- AddByte = $04244483; // opcode for ADD DWORD PTR [ESP+4], Shortint
- AddLong = $04244481; // opcode for ADD DWORD PTR [ESP+4], Longint
- type
- PAdjustSelfThunk = ^TAdjustSelfThunk;
- TAdjustSelfThunk = packed record
- case AddInstruction: Longint of
- AddByte: (AdjustmentByte: ShortInt);
- AddLong: (AdjustmentLong: Longint);
- end;
- PInterfaceMT = ^TInterfaceMT;
- TInterfaceMT = packed record
- QueryInterfaceThunk: PAdjustSelfThunk;
- end;
- TInterfaceRef = ^PInterfaceMT;
- var
- QueryInterfaceThunk: PAdjustSelfThunk;
- begin
- try
- Result := Pointer(I);
- if Assigned(Result) then
- begin
- QueryInterfaceThunk := TInterfaceRef(I)^.QueryInterfaceThunk;
- case QueryInterfaceThunk.AddInstruction of
- AddByte:
- Inc(PChar(Result), QueryInterfaceThunk.AdjustmentByte);
- AddLong:
- Inc(PChar(Result), QueryInterfaceThunk.AdjustmentLong);
- else
- Result := nil;
- end;
- end;
- except
- Result := nil;
- end;
- end;