﻿{"id":802,"date":"2010-01-23T09:07:39","date_gmt":"2010-01-23T01:07:39","guid":{"rendered":"http:\/\/www.tansoo.cn\/?p=802"},"modified":"2014-09-16T09:12:15","modified_gmt":"2014-09-16T01:12:15","slug":"delphi%e8%bf%87%e7%a8%8b%e5%87%bd%e6%95%b0%e4%bc%a0%e9%80%92%e5%8f%82%e6%95%b0%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/www.tansoo.cn\/?p=802","title":{"rendered":"Delphi\u8fc7\u7a0b\u51fd\u6570\u4f20\u9012\u53c2\u6570\u7684\u51e0\u79cd\u65b9\u5f0f"},"content":{"rendered":"<p>\u5728Delphi\u8fc7\u7a0b\u3001\u51fd\u6570\u4e2d\u4f20\u9012\u53c2\u6570\u51e0\u4e2a\u4fee\u9970\u7b26\u4e3aConst\u3001Var\u3001Out\u3002\u53e6\u4e00\u79cd\u4e0d\u52a0\u4fee\u9970\u7b26\u7684\u4e3a\u9ed8\u8ba4\u6309\u503c\u4f20\u9012\u53c2\u6570\u3002<\/p>\n<p>\u4e00\u3001\u9ed8\u8ba4\u65b9\u5f0f\u4ee5\u503c\u65b9\u5f0f\u4f20\u9012\u53c2\u6570 <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcNormal(Value: string);\r\nbegin\r\n  origNum := Value + ' Me';\r\n  lblReturn.Caption := origNum; \/\/ OrigNum\u4e3a'Hello Me'\r\n  lblOrig.Caption := Value; \/\/ Value\u4e3a'Hello'\r\nend;\r\n\r\n\/\/\u8c03\u7528\uff1a \r\norigNum:='Hello'; \r\nProcNormal(OrigNum);<\/pre>\n<p><!--more--><\/p>\n<p>\u4e8c\u3001\u4ee5Const\u65b9\u5f0f\u4f20\u9012\u53c2\u6570\uff0c\u8fd9\u4e2a\u53c2\u6570\u5728\u8c03\u7528\u8fc7\u7a0b\u4e2d\u4e0d\u80fd\u6539\u53d8\uff0c\u5e76\u4e14\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u88ab\u7f16\u8bd1\u5668\u4f18\u5316\uff0c\u4e00\u822c\u5efa\u8bae\u5c3d\u53ef\u80fd\u5730\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u3002 <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcConst(const Value: string);\r\nbegin\r\n  origNum := Value + ' Me';\r\n  lblReturn.Caption := origNum; \/\/ \u4e3a'Hello Me\u2018\r\n  lblOrig.Caption := Value; \/\/ \u4e3a'Hello Me'\r\nend;<\/pre>\n<p>\u4e09\u3001\u6309\u5f15\u7528\u65b9\u5f0f\u4f20\u9012\u53c2\u6570 <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcRef(var Value: string);\r\nbegin\r\n  origNum := Value + ' Me';\r\n  lblReturn.Caption := origNum; \/\/ \u4e3a'Hello Me\u2018\r\n  lblOrig.Caption := Value; \/\/ \u4e3a'Hello Me'\r\nend;<\/pre>\n<p>\u56db\u3001\u6309Out\u65b9\u5f0f\u4f20\u9012\u53c2\u6570\uff0c\u8fd9\u4e2a\u65b9\u5f0f\u4f20\u9012\u53c2\u6570\u65f6\uff0c\u53c2\u6570\u53ef\u4ee5\u4e0d\u88ab\u521d\u59cb\u5316\uff0c\u5373\u4f7f\u6709\u503c\u4e5f\u88ab\u5ffd\u89c6\uff0c\u5b83\u4e00\u822c\u7528\u4e8e\u8f93\u51fa,\u5b83\u53ef\u4ee5\u5b9e\u73b0\u5728\u4e00\u4e2a\u8fc7\u7a0b\u4e2d\u8fd4\u56de\u591a\u4e2a\u503c,\u6211\u4eec\u901a\u5e38\u5728\u5206\u5e03\u5f0f\u5bf9\u8c61\u6a21\u578b\uff0c\u5982COM\u4e2d\u4f7f\u7528\u5b83\u3002 <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcOut(out Value: string); \r\nbegin \r\n  origNum:=Value+' Me'; \r\n  lblReturn.Caption:=OrigNum;\/\/\u4e3a'Me' \r\n  lblOrig.Caption:=Value;\/\/\u4e3a'Me' \r\nend;<\/pre>\n<p>\u4e94\u3001\u65e0\u7c7b\u578b\u53c2\u6570\uff0c\u8fd9\u662f\u4e00\u79cd\u8f83\u4e3a\u7279\u6b8a\u7684\u65b9\u6cd5\uff0c\u53c2\u6570\u7684\u7c7b\u578b\u4e0d\u786e\u5b9a\uff0c\u53ea\u80fd\u7528Const\u3001Var\u3001Out\u4fee\u9970\uff0c\u4e0d\u80fd\u7528\u4e8e\u503c\u65b9\u5f0f\u4f20\u9012\u53c2\u6570\uff0c\u5177\u4f53\u4f7f\u7528\u793a\u4f8b\u5982\u4e0b\uff1a <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcUntype(const Value); \r\nbegin \r\n  origNum:=string(Value)+' Me'; \r\n  lblReturn.Caption:=OrigNum;\/\/\u4e3a'Hello Me' \r\n  lblOrig.Caption:=string(Value);\/\/\u4e3a'Hello Me' \r\nend;<\/pre>\n<p>\u516d\u3001\u9ed8\u8ba4\u53c2\u6570\uff0c\u5373\u5982\u679c\u6b64\u53c2\u6570\u5728\u8c03\u7528\u65f6\u672a\u63d0\u4f9b\u65f6\uff0c\u5c06\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002 <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcDefault(const Value, const DefaultValue:string=' 123'); \r\nbegin \r\n  origNum:=Value+' Me'+DefaultValue; \r\n  lblReturn.Caption:=OrigNum;\/\/\u4e3a'Hello Me 123' \r\n  lblOrig.Caption:=Value;\/\/ \u4e3a'Hello Me 123' \r\nend;<\/pre>\n<p>\u4e03\u3001\u5f00\u653e\u6570\u7ec4\u53c2\u6570\uff0c\u5373\u53c2\u6570\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u4e0d\u786e\u5b9a\u3002 <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcArray(const Value: array of string); \r\nvar \r\n  i:Integer; \r\nbegin \r\n  for i:=Low(Value) to High(Value) do \r\n    origNum:=OrigNum+Value[i];\/\/\u8c03\u7528\u540e\u4e3a'Hello abc dbd' \r\n  lblReturn.Caption:=OrigNum; \r\nend; \r\n\r\n\/\/\u8c03\u7528\uff1a \r\norigNum:='Hello'; \r\nProcArray([' abc ',' dbd']);<\/pre>\n<p>\u516b\u3001\u65e0\u7c7b\u578b\u5f00\u653e\u6570\u7ec4\u53c2\u6570\uff0c\u5373\u7c7b\u578b\u53ca\u5143\u7d20\u4e2a\u6570\u7686\u4e0d\u786e\u5b9a\u3002\u5728WIN32\u5e73\u53f0\u4e2d\uff0c\u8fd9\u4e2a\u53c2\u6570\u7684\u7c7b\u578b\u5b9e\u9645\u4e3aarray of TVarRec,\u5176\u4f7f\u7528\u793a\u4f8b\u5982\u4e0b: <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm1.ProcArrayConst(const Value: array of const);\r\nvar\r\n  i: Integer;\r\nbegin\r\n  for i := Low(Value) to High(Value) do\r\n    with Value[i] do\r\n      case VType of\r\n        vtAnsiString:\r\n          origNum := origNum + String(VAnsiString);\r\n        vtInteger:\r\n          origNum := origNum + IntToStr(VInteger);\r\n        vtBoolean:\r\n          origNum := origNum + BoolToStr(VBoolean);\r\n        vtChar:\r\n          origNum := origNum + VChar;\r\n        vtExtended:\r\n          origNum := origNum + FloatToStr(VExtended^);\r\n        vtString:\r\n          origNum := origNum + VString^;\r\n        vtPChar:\r\n          origNum := origNum + VPChar;\r\n        vtObject:\r\n          origNum := origNum + VObject.ClassName;\r\n        vtClass:\r\n          origNum := origNum + VClass.ClassName;\r\n        vtCurrency:\r\n          origNum := origNum + CurrToStr(VCurrency^);\r\n        vtVariant:\r\n          origNum := origNum + string(VVariant^);\r\n        vtInt64:\r\n          origNum := origNum + IntToStr(VInt64^);\r\n      end;\r\n  lblReturn.Caption := origNum; \/\/ \u8c03\u7528\u540e\u4e3a'Hello abc 3'\r\nend;\r\n\r\n\/\/ \u8c03\u7528\uff1a\r\n\r\norigNum := 'Hello';\r\nProcArrayConst([' abc ', 3]);<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5e38\u89c1\u51e0\u79cd\u4f20\u9012\u53c2\u6570\u7684\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Delphi\u8fc7\u7a0b\u3001\u51fd\u6570\u4e2d\u4f20\u9012\u53c2\u6570\u51e0\u4e2a\u4fee\u9970\u7b26\u4e3aConst\u3001Var\u3001Out\u3002\u53e6\u4e00\u79cd\u4e0d\u52a0\u4fee\u9970\u7b26\u7684\u4e3a\u9ed8\u8ba4\u6309\u503c\u4f20\u9012\u53c2\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[14],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-program","tag-delphi"],"_links":{"self":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=802"}],"version-history":[{"count":0,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts\/802\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}