{"id":6019,"date":"2025-03-28T10:57:36","date_gmt":"2025-03-28T02:57:36","guid":{"rendered":"https:\/\/blog.qdac.cc\/?p=6019"},"modified":"2025-03-28T10:57:37","modified_gmt":"2025-03-28T02:57:37","slug":"%e6%95%99%e7%a8%8b%e5%9c%a8-delphi-%e4%b8%ad%e5%ae%9e%e7%8e%b0%e7%b1%bb%e4%bc%bc-c-c-%e4%b8%ad-__offset-%e5%ae%8f%e7%9a%84%e6%95%88%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=6019","title":{"rendered":"[\u6559\u7a0b]\u5728 Delphi \u4e2d\u5b9e\u73b0\u7c7b\u4f3c C\/C++ \u4e2d __offset \u5b8f\u7684\u6548\u679c"},"content":{"rendered":"\n<p><strong>\u3010\u6ce8\u3011<\/strong>C\/C++ \u4e2d\u6709\u4e00\u4e2a __offset \u7528\u6765\u8ba1\u7b97\u4e00\u4e2a\u6570\u636e\u6210\u5458\u76f8\u5bf9\u4e8e\u8d77\u59cb\u5730\u5740\u504f\u79fb\u7684\u51fd\u6570\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u5b50\u7ed3\u70b9\u4e2d\uff0c\u4e0d\u7528\u8bb0\u5f55\u4e0a\u4e00\u7ea7\u7684\u5730\u5740\uff0c\u5c31\u53ef\u4ee5\u8fbe\u5230\u56de\u6eaf\u7236\u4e00\u7ea7\u7684\u5bf9\u8c61\u5b9e\u4f8b\u3002<\/p>\n\n\n\n<p>Delphi \u8981\u5b9e\u73b0\u7684\u540c\u6837\u7684\u6548\u679c\uff0c\u6709\u51e0\u79cd\u9009\u62e9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u57fa\u4e8e RTTI\uff0c\u901a\u8fc7\u5bf9\u5e94\u7684\u7c7b\u578b\u7684\u4fe1\u606f\uff0c\u7136\u540e\u53d6\u5bf9\u5e94\u7684 TRttiField \u7684 Offset \u7684\u503c\uff0c\u6b64\u79cd\u65b9\u6cd5\u6211\u4eec\u4e0d\u5728\u6b64\u5c55\u5f00\uff0c\u5177\u4f53\u53c2\u8003 QDAC \u6e90\u7801\u91cc\u5404\u79cd Rtti \u5e8f\u5217\u5316\u4ee3\u7801\u3002<\/li>\n\n\n\n<li>\u76f4\u63a5\u901a\u8fc7\u7b80\u5355\u7684\u6570\u636e\u8fd0\u7b97\u5b9e\u73b0\uff0c\u6211\u4eec\u77e5\u9053Delphi \u652f\u6301\u53d6\u5730\u5740\u64cd\u4f5c\uff0c\u6211\u4eec\u53ea\u9700\u8981\u53d6\u5f53\u524d\u6210\u5458\u7684\u5730\u5740\uff0c\u7136\u540e\u518d\u51cf\u53bb\u5f53\u524d\u6210\u5458\u76f8\u5bf9\u504f\u79fb\u5c31\u53ef\u4ee5\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type\n   TParent=record\n     FieldA:Integer;\n     FieldB:Integer;\n   end;\n   PParent=^TParent;\n...\n\/\/\nfunction GetParentAddr(const ABAddr:PInteger):PParent;inline;\nbegin\n  Result:=PParent(IntAddr(ABAddr)-IntPtr(@PParent(nil).FieldB);\nend;<\/code><\/pre>\n\n\n\n<p>\u662f\u4e0d\u662f\u6bd4\u7528 RTTI \u7b80\u5355\u591a\u4e86\uff0c\u800c\u4e14\u6548\u7387\u4e5f\u560e\u560e\u9ad8\u3002\u7531\u6b64\u5e26\u6765\u7684\u597d\u5904\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u9700\u8981\u5355\u72ec\u5b58\u50a8\u6307\u5411\u7236\u7684\u5730\u5740\uff0c\u590d\u5408\u6570\u636e\u7c7b\u578b\u7684\u5b9a\u4e49\u66f4\u7b80\u6d01\u3002<\/li>\n\n\n\n<li>\u4e0d\u9700\u8981\u7ef4\u62a4\u6307\u5411\u7236\u7684\u5730\u5740\uff0c\u4ee3\u7801\u4e5f\u4f1a\u66f4\u7b80\u6d01\u3002<\/li>\n\n\n\n<li>\u7531\u4e8e\u53ea\u662f\u7b80\u5355\u7684\u51cf\u6cd5\u8fd0\u7b97\uff0c\u6548\u7387\u5f88\u9ad8\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u3010\u9650\u5236\u3011<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53ea\u9002\u7528\u4e8e\u590d\u5408\u7c7b\u578b\uff0c\u5f53\u7136\u7b80\u5355\u7c7b\u578b\u4e5f\u6ca1\u6709\u610f\u4e49\u3002<\/li>\n\n\n\n<li>\u8981\u660e\u786e\u77e5\u9053\u7236\u5bb9\u5668\u7684\u7c7b\u578b\uff0c\u5982\u4e0a\u9762\u4f60\u5f97\u77e5\u9053\u662f\u7236\u7684\u7c7b\u578b\u662f PParent\uff0c\u5982\u679c\u7236\u5bb9\u5668\u662f\u591a\u79cd\u7c7b\u578b\uff0c\u4f60\u5fc5\u9700\u6709\u529e\u6cd5\u533a\u5206\u6216\u8005\u5c06\u7236\u5bf9\u8c61\u7684\u6210\u5458\u5730\u5740\u5bf9\u9f50\uff0c\u4fdd\u8bc1\u50cf\u4e0a\u9762\u7684 FieldB \u5728\u5185\u5b58\u4e2d\u504f\u79fb\u662f\u540c\u4e00\u4e2a\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li>\u6ca1\u6709\u5bb9\u9519\u7a7a\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u793a\u4f8b\u4e2d\u7528\u6237\u4f20\u7684 ABAddr \u5730\u5740\u4e0d\u662f\u4e00\u4e2a TParent \u7c7b\u578b\u7684\u6210\u5458\u7684\u5730\u5740\uff0c\u90a3\u4e48\u4f60\u4ecd\u5c06\u5f97\u5230\u4e00\u4e2a PParent \u5730\u5740\uff0c\u4f46\u5b83\u660e\u663e\u662f\u65e0\u6548\u7684\uff0c\u4f1a\u51fa\u73b0 AV \u9519\u8bef\u3002<strong>\u5f53\u7136\u8fd9\u4e00\u70b9\u9700\u8981\u7528\u6237\u7f16\u7801\u9644\u9875\u6765\u4fdd\u8bc1\u7684\uff0c\u65e0\u8bba\u662f\u4f7f\u7528 RTTI \u8fd8\u662f\u8fd9\u79cd\u76f4\u63a5\u8ba1\u7b97\uff0c\u8fd9\u4e2a\u90fd\u662f\u5f00\u53d1\u4eba\u5458\u7684\u8d23\u4efb<\/strong>\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u6ce8\u3011C\/C++ \u4e2d\u6709\u4e00\u4e2a __offs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8,603],"tags":[],"class_list":["post-6019","post","type-post","status-publish","format-standard","hentry","category-delphi","category-603"],"views":1132,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/6019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6019"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/6019\/revisions"}],"predecessor-version":[{"id":6020,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/6019\/revisions\/6020"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}