六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 194|回复: 0

JCL中由接口获得对象的方法

[复制链接]

升级  47.05%

629

主题

629

主题

629

主题

探花

Rank: 6Rank: 6

积分
1941
 楼主| 发表于 2013-2-8 00:42:58 | 显示全部楼层 |阅读模式
我原本并不想单独发以下JCL的方法,可是想到很多人可能还是不知道的。另外,从我博客的回复上看,很多人也愿意去了解一下,特此贴出JCL中的代码。
<style type="text/css"><!--body { color: #000000; background-color: #ffffff; }.pas1-assembler { background-color: #ffffff; color: #000000; }.pas1-character { background-color: #ffffff; color: #ff00ff; }.pas1-comment { background-color: #ffffff; color: #008000; font-style: italic; }.pas1-float { background-color: #ffffff; color: #ff0000; }.pas1-hexadecimal { background-color: #ffffff; color: #ff0000; }.pas1-identifier { background-color: #ffffff; color: #000000; }.pas1-number { background-color: #ffffff; color: #ff0000; }.pas1-preprocessor { background-color: #ffffff; color: #008000; font-style: italic; }.pas1-reservedword { background-color: #ffffff; color: #000080; font-weight: bold; }.pas1-space { background-color: #ffffff; color: #000000; }.pas1-string { background-color: #ffffff; color: #ff00ff; }.pas1-symbol { background-color: #ffffff; color: #000000; }--></style>
<blockquote><span style=""><span class="pas1-comment"><div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">//===Interfaceinformation==================================================

functionGetImplementorOfInterface(
constI:IInterface):TObject;
...{TODO-cDOC:OriginalcodebyHallvardVassbotn}
...{TODO-cTesting:Checktheimplemetationforanyfurtherversionofcompiler}
const
AddByte
=$04244483;//opcodeforADDDWORDPTR[ESP+4],Shortint
AddLong=$04244481;//opcodeforADDDWORDPTR[ESP+4],Longint
type
PAdjustSelfThunk
=^TAdjustSelfThunk;
TAdjustSelfThunk
=packedrecord
caseAddInstruction:Longintof
AddByte:(AdjustmentByte:ShortInt);
AddLong:(AdjustmentLong:Longint);
end;
PInterfaceMT
=^TInterfaceMT;
TInterfaceMT
=packedrecord
QueryInterfaceThunk:PAdjustSelfThunk;
end;
TInterfaceRef
=^PInterfaceMT;
var
QueryInterfaceThunk:PAdjustSelfThunk;
begin
try
Result:
=Pointer(I);
ifAssigned(Result)then
begin
QueryInterfaceThunk:
=TInterfaceRef(I)^.QueryInterfaceThunk;
caseQueryInterfaceThunk.AddInstructionof
AddByte:
Inc(PChar(Result),QueryInterfaceThunk.AdjustmentByte);
AddLong:
Inc(PChar(Result),QueryInterfaceThunk.AdjustmentLong);
else
Result:
=nil;
end;
end;
except
Result:
=nil;
end;
end;
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表