{"id":587,"date":"2014-09-14T14:10:10","date_gmt":"2014-09-14T06:10:10","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=587"},"modified":"2015-06-09T13:12:31","modified_gmt":"2015-06-09T05:12:31","slug":"%e3%80%90mybean-%e5%bc%80%e6%ba%90%e6%a1%86%e6%9e%b6%e3%80%91%e8%bf%9b%e8%a1%8c%e7%ae%80%e5%8d%95%e7%9a%84%e9%80%bb%e8%be%91%e6%8f%92%e4%bb%b6%e6%bc%94%e7%a4%ba%e5%9c%a8%e6%8e%a7%e5%88%b6%e5%8f%b0","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=587","title":{"rendered":"\u3010MyBean-\u5f00\u6e90\u6846\u67b6\u3011\u8fdb\u884c\u7b80\u5355\u7684\u903b\u8f91\u63d2\u4ef6(\u6f14\u793a\u5728\u63a7\u5236\u53f0\u4e2d\u5e94\u7528)"},"content":{"rendered":"<p>\u3010\u8bf4\u660e\u3011<\/p>\n<p>\u5f88\u591a\u65f6\u5019\u5927\u5bb6\u8ba4\u4e3a\u5ba2\u6237\u7aef\u63d2\u4ef6\u4e00\u822c\u662f\u7a97\u4f53\u3002\u5176\u5b9e\u4e0d\u7136\uff0c\u5f88\u591a\u529f\u80fd\u90fd\u53ef\u4ee5\u770b\u6210\u662f\u63d2\u4ef6\uff0c\u6bd4\u5982\u4e00\u4e2a\u5355\u636e\u7684\u5ba1\u6279\u529f\u80fd\uff0c\u4e00\u4e2a\u5355\u636e\u4e0a\u9762\uff0c\u5355\u4ef7\u7684\u83b7\u53d6\u529f\u80fd\uff0c\u90fd\u53ef\u4ee5\u770b\u6210\u662f\u63d2\u4ef6\uff0c\u7136\u540e\u540e\u671f\u901a\u8fc7\u914d\u7f6e\uff0c\u53ef\u4ee5\u7075\u6d3b\u8fdb\u884c\u5207\u6362\u3002MyBean\u652f\u6301\u8fd9\u79cd\u63d2\u4ef6\uff0c\u652f\u6301\u8fd9\u79cd\u7eaf\u903b\u8f91\u7684\u63d2\u4ef6\u3002\u5269\u4e0b\u7684\u662f\u9700\u8981\u81ea\u5df1\u53bb\u5236\u5b9a\u6267\u884c\u903b\u8f91\u7684\u534f\u8bae\uff0c\u8fd9\u4e2aDEMO\u5c31\u662f\u5c55\u793a\u5982\u679c\u8fdb\u884c\u903b\u8f91\u63d2\u4ef6\u7684\u7f16\u5199\u3002<\/p>\n<p>\u3010DEMO\u8bbe\u8ba1\u3011<\/p>\n<p>\u8be5DEMO\u5728\u8c03\u7528DLL\u7684\u4e00\u4e2a\u63d2\u4ef6\u5b8c\u6210\u4e24\u4e2a\u7b80\u5355\u6570\u5b57\u7684\u7b80\u5355\u5408\u8ba1\uff0c\u7136\u540e\u53ef\u4ee5\u7531\u5176\u4ed6\u63d2\u4ef6\u8c03\u7528\u65e5\u5fd7\u63d2\u4ef6\u8f93\u51fa\u529f\u80fd\u3002<\/p>\n<p>\u5148\u5236\u5b9a\u63a5\u53e3\u534f\u8bae(uILogic.pas)\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">type\r\n  \/\/\/ &lt;summary&gt;\r\n  \/\/\/   \u5408\u8ba1\u63d2\u4ef6\u63a5\u53e3\r\n  \/\/\/ &lt;\/summary&gt;\r\n  ISumExp = interface(IInterface)\r\n    ['{D02C3764-1231-46EC-8C74-95DFBF2A1ED5}']\r\n    function sum(i:Integer; j:Integer):Integer; stdcall;\r\n  end;\r\n\r\n  \/\/\/ &lt;summary&gt;\r\n  \/\/\/   \u65e5\u5fd7\u63d2\u4ef6\u63a5\u53e3\r\n  \/\/\/ &lt;\/summary&gt;\r\n  IMyBeanLogger = interface(IInterface)\r\n    ['{B872909D-99FF-47B9-A3F9-8CB9C26A8FD5}']\r\n    procedure LogMessage(s: PAnsiChar); stdcall;\r\n  end;<\/pre>\n<p>&nbsp;<\/p>\n<p>2.\u6ce8\u518c\u65e5\u5fd7\u63d2\u4ef6\uff0c \u7531EXE\u63d0\u4f9b\u5b9e\u73b0\uff0c\u5728EXE\u4e2d\u6ce8\u518c\u65e5\u5fd7\u63d2\u4ef6(uMyBeanLoggerImpl.pas)\u3002<\/p>\n<pre class=\"lang:delphi decode:true \">initialization\r\n  \/\/\/\u6ce8\u518c\u65e5\u5fd7\u63d2\u4ef6\r\n  beanFactory.RegisterBean('mybeanLogger', TMyBeanLoggerImpl);<\/pre>\n<p>&nbsp;<\/p>\n<p>3.\u903b\u8f91\u63d2\u4ef6\u7684\u5b9e\u73b0(ISumExp\u63a5\u53e3\u7684\u5b9e\u73b0)<\/p>\n<pre class=\"lang:delphi decode:true\">function TSumExpImpl.sum(i, j: Integer): Integer;\r\nbegin\r\n  Result := i + j;\r\n\r\n  (TMyBeanFactoryTools.getBean('mybeanLogger') as IMyBeanLogger).LogMessage('dll\u63d2\u4ef6\u8c03\u7528mybeanLogger\u63d2\u4ef6\uff0c\u8f93\u51fa\u4e00\u4e9b\u4fe1\u606f');\r\nend;<\/pre>\n<p>4.\u6ce8\u518c\u903b\u8f91\u63d2\u4ef6<\/p>\n<pre class=\"lang:delphi decode:true \">library logicBean;\r\n\r\nuses\r\n  SysUtils,\r\n  mybean.core.beanFactoryForNoVcl,\r\n  Classes,\r\n  uSumExpImpl in 'uSumExpImpl.pas',\r\n  uILogic in '..\\common\\uILogic.pas';\r\n\r\n{$R *.res}\r\n\r\nbegin\r\n  beanFactory.RegisterBean('sumExp', TSumExpImpl);\r\nend.<\/pre>\n<p>5.\u7f16\u8bd1\u51fa\u6765\u7684DLL\u548cEXE\u653e\u4e00\u8d77\u5c31\u53ef\u4ee5\u8fd0\u884c\u4e86<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/image12.png\"><img loading=\"lazy\" decoding=\"async\" style=\"padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;\" title=\"image\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/image_thumb12.png\" alt=\"image\" width=\"613\" height=\"403\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u8be5DEMO\u53ea\u662f\u629b\u7816\uff0c\u60f3\u60f3\u81ea\u5df1\u7684\u7cfb\u7edf\u4e2d\u53ef\u4ee5\u628a\u54ea\u4e9b\u529f\u80fd\u505a\u6210\u903b\u8f91\u63d2\u4ef6\u2026\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u8bf4\u660e\u3011 \u5f88\u591a\u65f6\u5019\u5927\u5bb6\u8ba4\u4e3a\u5ba2\u6237\u7aef\u63d2\u4ef6\u4e00\u822c [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","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":[53],"tags":[453],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-mybean","tag-mybean"],"views":3816,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/587","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\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=587"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions"}],"predecessor-version":[{"id":2569,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions\/2569"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}