{"id":4551,"date":"2017-04-17T01:52:15","date_gmt":"2017-04-16T17:52:15","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4551"},"modified":"2017-04-17T01:55:34","modified_gmt":"2017-04-16T17:55:34","slug":"delphi%e4%b8%ad%e4%b8%8d%e5%90%8c%e7%9a%84%e5%8a%a8%e6%80%81%e6%95%b0%e7%bb%84%e5%8f%98%e9%87%8f%e5%85%b1%e4%ba%ab%e5%86%85%e5%ad%98","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4551","title":{"rendered":"DELPHI\u4e2d\u4e0d\u540c\u7c7b\u578b\u7684\u52a8\u6001\u6570\u7ec4\u53d8\u91cf\u5171\u4eab\u5185\u5b58"},"content":{"rendered":"<p><strong>\u573a\u666f<\/strong>\uff1a \u5047\u5982\u6211\u4eec\u8981\u8c03\u7528A\u51fd\u6570 procedure A( aBytes:Tbytes).<\/p>\n<p>\u4f60\u624b\u4e0a\u73b0\u5728\u53ea\u6709\u4e00\u4e2aSTRING, \u6216\u8005\u5176\u4ed6\u6570\u7ec4\u7c7b\u578b\uff0c\u6bd4\u5982Array of char. array of integer..\u4e00\u822c\u7684\u8fc7\u7a0b\u5c31\u662f\uff0c\u9996\u5148\u628a\u4f60\u624b\u4e0a\u7684\u6570\u7ec4\u7c7b\u578b\u8f6c\u6362\u6210\u7b26\u5408A\u8c03\u7528\u7684\u9700\u8981\u7684\u7c7b\u578bTBYTES\uff0c\uff0c\u5176\u5b9e\u5f88\u591a\u65f6\u5019\u6211\u4eec\u9700\u8981\u8981\u8fd9\u4e2aTBYTES\u7eaf\u7cb9\u662f\u4e3a\u4e86\u5f97\u5230\u4e00\u4e2aA\u51fd\u6570\u8fd0\u884c\u7684\u7ed3\u679c\uff0cBYTES\u5176\u5b9e\u5e76\u6ca1\u6709\u4ec0\u4e48\u7528\uff0c\u53ea\u662f\u4e00\u4e2a\u4e2d\u95f4\u6570\u636e\u3002\u4f46\u662f\u6709\u6ca1\u6709\u60f3\u8fc7\uff0c\u8f6c\u6362\u7684\u8fc7\u7a0b\u5176\u5b9e\u9700\u8981\u5185\u5b58\u5f00\u9500\u7684\uff0c\u5185\u5b58\u8981\u5206\u914d\uff0c\u6570\u636e\u8981\u590d\u5236\uff0c\u6700\u540e\u9500\u6bc1\u3002\u80fd\u4e0d\u80fd\u628a\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u7ec4\u5171\u4eab\u5728\u4e00\u5757\u5185\u5b58\u4e0a\u3002\u6bd4\u5982STRING,\u65e2\u53ef\u4ee5\u5f53TBYTES\u7528\uff0c\u4e5f\u53ef\u4ee5\u5f53 \u6bd4\u5982ARRAY OF INTEGER. \u7b54\u6848\u662f\u80af\u5b9a\u7684\u3002<\/p>\n<p><strong>\u73a9\u6cd5\u57fa\u7840\u5206\u6790<\/strong>\uff1a\u4e00\u4e2a\u52a8\u6001\u6570\u7ec4\u7684\u4e09\u8981\u7d20\uff0c\u5185\u5b58\u9996\u5730\u5740\uff0c\u957f\u5ea6\uff0c\u5143\u7d20\u5927\u5c0f\u3002<\/p>\n<p><strong>\u5185\u5b58\u9996\u5730\u5740<\/strong>\uff1a\u7b80\u5355\uff0c\u5185\u5b58\u5730\u5740\u662f\u53ef\u4ee5\u76f8\u4e92\u8d34\u7684(\u8d34\u5c31\u662f\u6307\u9488\u5171\u540c\u6307\u5411\u4e00\u4e2a\u5730\u65b9\uff09\u3002\u76f4\u63a5\u8d4b\u503c\u5c31\u884c\u3002<\/p>\n<p>var\u00a0 Abytes:Tbytes; aIntegers: array of integer;<\/p>\n<p>\u8d34\uff1a Abytes:=Pointer(aIntegers);<\/p>\n<p><strong>\u00a0\u5143\u7d20\u5927\u5c0f\uff1a<\/strong>\u7b80\u5355\uff0c SIZEOF\uff08BYTE\uff09\uff0csizeof\uff08ineteger\uff09;<\/p>\n<p>\u5269\u4e0b\u5c31\u662f\u957f\u5ea6\u5728\u54ea\u91cc\uff1f<\/p>\n<p><strong>\u957f\u5ea6\uff1a<\/strong><\/p>\n<p>DELPHI\u7684\u52a8\u6001\u6570\u7ec4\u7ba1\u7406\u6709\u5934\u90e8\u3002\u4f4d\u7f6e\u5c31\u5728\u52a8\u6001\u6570\u7ec4\u6307\u9488\u7684\u524d\u9762\u3002\u5934\u90e8\u6709\u4ec0\u4e48\u3002\u3002\u6bcf\u4e2a\u7248\u672c\u90fd\u4e0d\u4e00\u6837\u3002\u4f46\u662f\u4e00\u6837\u7684\u662f\uff0c\u52a8\u6001\u6570\u7ec4\u7684\u524d4\u4e2a\u5b57\u8282\u5c31\u662f\u52a8\u6001\u6570\u7ec4\u7684\u957f\u5ea6(\u5305\u62ec\u5b57\u7b26\u4e32\u4e5f\u662f\u5982\u6b64\uff09\u3002<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u6109\u5feb\u7684\u73a9\u800d\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u5217\u6587\u7ed9\u51fa\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32S\u53d8\u6210TBYTES S\u7684\u4f8b\u5b50\uff0c\u4f46\u662fA\u548cS\u5171\u4eab\u4e00\u5757\u5185\u5b58\u3002 \u4e5f\u5c31\u662f\u8bf4\u53ea\u6709\u7684\u7c7b\u578b\u8f6c\u6362\u6ca1\u6709\u6d89\u53ca\u5230\u5185\u5b58\u7684\u65b0\u7684\u5206\u914d\u3002<\/p>\n<p>function <strong>NewtypeFunction<\/strong>(const A: tbytes): string;<br \/>\nbegin<br \/>\nSystem.SetLength(Result, System.Length(A) shr 1);<br \/>\nSystem.Move(A[0], result[1], Length(A));<br \/>\nend;<\/p>\n<p>procedure TForm1.btn1Click(Sender: TObject);<br \/>\nvar<br \/>\n<strong>A: TBytes;<\/strong><br \/>\n<strong> S: string;<\/strong><br \/>\nbegin<br \/>\n\/\/ A \u548cS\u5171\u4eab\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u3002\u8fbe\u5230\u7c7b\u578b\u8f6c\u6362\u3002<br \/>\nS := &#8216;\u6211\u7684agbc&#8217;;<br \/>\nA := Pointer(@S[1]); \/\/ \u76f4\u63a5\u6307\u9488\u8d34\u4e0a\u53bb \uff0c\u5171\u540c\u6307\u5411\u4e00\u5757\u5185\u5b58<br \/>\nPInteger(PByte(A) &#8211; 4)^ := Length(S) shl 1; \/\/\u8131\u79bbD\u5bf9TBYTES\u7684\u7ba1\u7406\uff0c\u4fee\u6b63TBYTES\u7684\u957f\u5ea6<br \/>\nShowMessage(<strong>NewtypeFunction<\/strong>(A)); \/\/ TBYTES\u6d3b\u4e86\u3002 \u80fd\u7528\u3002<br \/>\nPInteger(PByte(A) &#8211; 4)^ := Length(A) shr 1; \/\/ \u6062\u590d S\u5b57\u7b26\u4e32\u957f\u5ea6\u3002<br \/>\nA := nil;\/\/ \u63d2\u53bb\u5c41\u80a1<\/p>\n<p>end;<\/p>\n<p>\u7279\u522b\u732e\u7ed9\u8001\u7a0b\u5e8f\u5458\uff0c\u8fc7\u53bbD7\u90fd\u662f\u7528PANSICHAR\u7684\u5e72\u6d3b\uff0c\u73b0\u5728D\u5e93\u5f88\u591a\u51fd\u6570\u9700\u8981TBYTES\u7684\u5e72\u6d3b\u3002\u3002\u4ee3\u7801\u5347\u7ea7\u3002\u3002\u5403\u4e00\u58f6<\/p>\n<p>\u7ecf\u5e38\u78b0\u5230\u8fd9\u6837\u7684\u573a\u666f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b81\u6ce2\u7a7a\u3002\uff08Q:9534557\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u573a\u666f\uff1a \u5047\u5982\u6211\u4eec\u8981\u8c03\u7528A\u51fd\u6570 proce [&hellip;]<\/p>\n","protected":false},"author":113,"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":[8],"tags":[],"class_list":["post-4551","post","type-post","status-publish","format-standard","hentry","category-delphi"],"views":4779,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4551","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\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4551"}],"version-history":[{"count":3,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4551\/revisions"}],"predecessor-version":[{"id":4554,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4551\/revisions\/4554"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}