{"id":4950,"date":"2018-09-02T10:13:34","date_gmt":"2018-09-02T02:13:34","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4950"},"modified":"2018-09-02T10:15:16","modified_gmt":"2018-09-02T02:15:16","slug":"%e3%80%90%e6%95%99%e7%a8%8b%e3%80%91delphi-%e4%b8%ad%e5%a6%82%e4%bd%95%e8%ae%bf%e9%97%ae%e5%8f%a6%e4%b8%80%e4%b8%aa%e7%b1%bb%e4%b8%ad%e5%88%b0%e7%a7%81%e6%9c%89%e6%88%90%e5%91%98%e6%96%b9%e6%b3%95-n","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4950","title":{"rendered":"\u3010\u6559\u7a0b\u3011delphi \u4e2d\u5982\u4f55\u8bbf\u95ee\u53e6\u4e00\u4e2a\u7c7b\u4e2d\u5230\u79c1\u6709\u6210\u5458\u65b9\u6cd5 N \u5408 1"},"content":{"rendered":"<p>\u6b64\u6587\u662f\u53c2\u8003 \u00a0<a href=\"http:\/\/rvelthuis.blogspot.tw\/2018\/01\/accessing-private-methods-of-another.html\">\u539f\u6587\u94fe\u63a5<\/a>\u00a0\u548c\u7fa4\u53cb\u53ca\u4f5c\u8005\u81ea\u5df1\u66fe\u7ecf\u7528\u8fc7\u7684\u65b9\u6cd5\u7b80\u5355\u603b\u7ed3\uff0c\u611f\u8c22\u7fa4\u5185\u7684\u670b\u53cb\u548c\u539f\u6587\u4f5c\u8005\u3002\u53e6\u5916\uff0c<strong>\u6b64\u6587\u4e2d\u6240\u8c13\u7684\u8bbf\u95ee\u53e6\u4e00\u4e2a\u7c7b\u7684\u79c1\u6709\u6210\u5458\uff0c\u53e6\u4e00\u4e2a\u7c7b\u5e76\u4e0d\u5728\u540c\u4e00\u5355\u5143\uff0c\u5728\u540c\u4e00\u5355\u5143\u5185\u7684\u79c1\u6709\u6210\u5458 Delphi \u4e5f\u662f\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u7684\uff0c\u4e0d\u9700\u8981\u7ed5\u5708\u5b50\u3002<\/strong><\/p>\n<h4>1\u3001\u6700\u6613\u7528\u7684\u65b9\u6cd5\uff1aclass helper + with self<\/h4>\n<p>\u521b\u5efa\u4e00\u4e2a\u5bf9\u5e94\u7c7b\u7684 class helper\uff0c\u7136\u540e\u5728\u5176\u4e2d\u7528 with self do \u6765\u8bbf\u95ee\u5176\u79c1\u6709\u6210\u5458\u3002\u4e0d\u8fc7\u8fd9\u4e2a\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u7b97 bug\uff0c\u5982\u679c\u7b97\u7684\u8bdd\uff0c\u5b98\u65b9\u53ef\u80fd\u4f1a\u5728\u4ee5\u540e\u4fee\u6b63\uff0c\u5982\u679c\u4e0d\u7b97\uff0c\u5927\u5bb6\u5c31\u8fd9\u4e48\u7528\u5427\u3002<\/p>\n<pre class=\"lang:delphi decode:true\">type\r\n   TMyHelperForClass=class helper for TMyClass\r\n   ...\r\n   end;\r\n\r\n...TMyHelperForClass.xxxx...\r\nbegin\r\n...\r\nwith Self do\r\n   begin\r\n   \/\/\u5728\u8fd9\u91cc\u5c31\u53ef\u4ee5\u8bbf\u95ee TMyClass \u7684\u79c1\u6709\u6210\u5458\u4e86\r\n   end\r\nend;\r\n<\/pre>\n<h4>2\u3001\u4f7f\u7528 TMethod \u65b9\u6cd5\u8bbf\u95ee\u79c1\u6709\u51fd\u6570<\/h4>\n<p>\u8fd9\u4e2a\u672c\u8d28\u4e0a\u6765\u8bf4\uff0c\u5c31\u662f\u8bbe\u7f6e TMethod.Code \u548c Data \u6210\u5458\u7684\u5730\u5740\uff0c\u5176\u4e2d Code \u5bf9\u5e94\u79c1\u6709\u51fd\u6570\u5730\u5740\uff0c\u7136\u540e Data \u6307\u5411 Self\uff0c\u7136\u540e\u58f0\u660e\u4e0b\u79c1\u6709\u65b9\u6cd5\u7684\u7c7b\u578b\uff0c\u8f6c\u6362\u4e0b\u5c31\u597d\u3002<\/p>\n<pre class=\"lang:delphi decode:true\">type\r\n   TPrivateMethodType=... of object;\r\n...\r\nvar\r\n   AMethod:TMethod;\r\n   AInvoke:TPrivateMethodType absolute AMethod;\r\nbegin\r\nAMethod.Code:=@TMyClass.PrivateMethodName;\r\nAMethod.Data:=Self;\r\nAInvoke(...);\r\nend;<\/pre>\n<p>\u5f53\u7136\uff0c\u8fd9\u4e2a\u4ec5\u9650\u4e8e\u79c1\u6709\u51fd\u6570\uff0c\u4e0d\u5305\u542b\u6210\u5458\u3002<\/p>\n<h4>3\u3001\u6700\u4fdd\u5b88\u7684\u7528\u6cd5\uff1aRTTI<\/h4>\n<p>\u5229\u7528\u65b0\u7248 Delphi \u7684 Rtti \u652f\u6301\uff0c\u53ef\u4ee5\u83b7\u53d6\u79c1\u6709\u6210\u5458\u7684\u5730\u5740\uff0c\u5e76\u8fdb\u884c\u8c03\u7528\u3002\u6548\u7387\u4e0d\u5982\u524d\u9762\u51e0\u79cd\u65b9\u6cd5\uff0c\u4f46\u76f8\u5bf9\u6765\u8bf4\uff0c\u66f4\u53ef\u63a7\u4e00\u4e9b\u3002\u76f4\u63a5\u642c\u8fc7\u6765 qdac_fmx_vkhelper \u7684\u4ee3\u7801\uff0c\u7ed9\u5927\u5bb6\u53c2\u8003\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">procedure UpdateAndroidKeyboardServiceState;\r\n  var\r\n    ASvc: IFMXVirtualKeyboardService;\r\n    AContext: TRttiContext;\r\n    AType: TRttiType;\r\n    AField: TRttiField;\r\n    AInst: TVirtualKeyboardAndroid;\r\n  begin\r\n    if not Assigned(FVKState) then\r\n    begin\r\n      if (not Assigned(Screen.FocusControl)) and\r\n        TPlatformServices.Current.SupportsPlatformService\r\n        (IFMXVirtualKeyboardService, ASvc) then\r\n      begin\r\n        AInst := ASvc as TVirtualKeyboardAndroid;\r\n        AContext := TRttiContext.Create;\r\n        AType := AContext.GetType(TVirtualKeyboardAndroid);\r\n        AField := AType.GetField('FState');\r\n        if AField.GetValue(AInst).AsOrdinal &lt;&gt; 0 then\r\n        begin\r\n          FVKState := PByte(AInst);\r\n          Inc(FVKState, AField.Offset);\r\n        end;\r\n      end;\r\n    end;\r\n    if Assigned(FVKState) and (FVKState^ &lt;&gt; 0) then\r\n      FVKState^ := 0;\r\n  end;<\/pre>\n<h4>4\u3001\u6709\u98ce\u9669\u7684\u65b9\u6cd5\uff1a\u5957\u5a03<\/h4>\n<p>\u5957\u5a03\u8fd9\u79cd\u529e\u6cd5\uff0c\u5728\u4ee5\u524d\u7528\u8fc7\uff0c\u56e0\u4e3a\u8981\u6c42\u6210\u5458\u7684\u5e03\u5c40\u548c\u539f\u59cb\u7684\u51fd\u6570\u4e00\u6837\uff0c\u6240\u4ee5\u6211\u89c9\u5f97\u4e07\u4e00\u539f\u59cb\u7c7b\u5347\u7ea7\uff0c\u8fd9\u5757\u90fd\u5f97\u8ddf\u7740\u6539\uff0c\u6240\u4ee5\u4e0d\u592a\u63a8\u8350\u8fd9\u4e48\u7528\u3002\u8fd9\u79cd\u4e00\u822c\u662f\u7528\u6765\u8bbf\u95ee\u79c1\u6709\u6210\u5458\u53d8\u91cf\u65f6\u6bd4\u8f83\u65b9\u4fbf\uff0c\u5982\u679c\u662f\u79c1\u6709\u51fd\u6570\uff0c\u5219\u7531\u4e8e\u4ee3\u7801\u5730\u5740\u4e0d\u4e00\u6837\uff0c\u4e0d\u80fd\u76f4\u63a5\u7528\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u8ba1\u7b97\u6210\u5458\u51fd\u6570\u5730\u5740\u504f\u79fb\u7684\u65b9\u5f0f\uff0c\u6765\u5b8c\u6210\u8c03\u7528\u3002\u603b\u4f53\u6765\u8bf4\uff0c\u5957\u5a03\u867d\u597d\uff0c\u614e\u7528\u4e3a\u4f73\u3002<\/p>\n<h4>5\u3001\u6700\u96be\u7528\u7684\u65b9\u6cd5\uff1a\u6c47\u7f16<\/h4>\n<p>\u597d\u5427\uff0c\u8fd9\u89c9\u5f97\u8fd9\u4e2a\u5df2\u7ecf\u8d85\u8fc7\u5927\u90e8\u5206\u666e\u901a\u7a0b\u5e8f\u5458\u7684\u80fd\u529b\u4e86\uff0casm JMP \u6307\u4ee4\u8df3\u8f6c\u5230\u76ee\u6807\u5730\u5740\u53bb\u6267\u884c\u5c31\u53ef\u4ee5\u8c03\u7528\u51fd\u6570\uff0c\u5b9e\u9645\u4e0a\u76f4\u63a5asm\u00a0call \u5e94\u8be5\u4e5f\u662f\u4e00\u6837\u7684\u3002\u5982\u679c\u51fd\u6570\u6ca1\u6709\u53c2\u6570\u8fd8\u597d\uff0c\u6709\u7684\u8bdd\uff0c\u4f60\u5f97\u7814\u7a76\u4e0b\u5982\u4f55\u5165\u6808\/\u51fa\u6808\/\u6808\u5e73\u5e73\u8861\u7684\u95ee\u9898\uff0c\u5bf9\u4e8e\u5927\u90e8\u5206\u8fd8\u662f\u7b97\u4e86\u5427\u3002\u539f\u6587\u6709\u4f8b\u5b50\uff0c\u4e0d\u8fc7\u6211\u89c9\u5f97\u8fd8\u662f\u201c\u5c31\u8fd9\u6837\u7b97\u4e86\u5427\uff0c\u5c31\u8fd9\u6837\u5fd8\u5b50\u5427\uff0c\u8be5\u653e\u5c31\u653e\uff0c\u518d\u60f3\u4e5f\u6ca1\u6709\u7528\uff0c\u50bb\u50bb\u7b49\u5f85\u2026\u2026\u201d\uff0c\u6709\u5531\u51fa\u6765\u7684\u8bf4\u660e\u662f\u540c\u9f84\u4eba\uff0c\u8001\u4e86~~~~<\/p>\n<p>\u3010\u5176\u5b83\u3011<\/p>\n<p>\u8bbf\u95ee\u4fdd\u62a4\u6210\u5458\u7684\u529e\u6cd5\u5c31\u7b80\u5355\u591a\u4e86\uff0c\u76f4\u63a5\u7528class helper \u6216\u8005\u662f\u5b9e\u73b0\u4e00\u4e2a\u5b50\u7c7b\uff08\u8fd9\u4e2a\u5b50\u7c7b\u5565\u4e5f\u4e0d\u9700\u8981\u505a\uff0c\u53ea\u662f\u7236\u7c7b\u7684\u4e00\u4e2a\u8f6c\u6362\u5668\uff09\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6b64\u6587\u662f\u53c2\u8003 \u00a0\u539f\u6587\u94fe\u63a5\u00a0\u548c\u7fa4\u53cb\u53ca\u4f5c\u8005\u81ea\u5df1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","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":[755],"class_list":["post-4950","post","type-post","status-publish","format-standard","hentry","category-delphi","category-603","tag-755"],"views":3992,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4950","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=4950"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4950\/revisions"}],"predecessor-version":[{"id":4952,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4950\/revisions\/4952"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}