{"id":398,"date":"2009-05-17T10:27:00","date_gmt":"2009-05-17T02:27:00","guid":{"rendered":""},"modified":"2013-11-17T19:21:16","modified_gmt":"2013-11-17T11:21:16","slug":"delphi%e7%9a%84%e8%bf%90%e7%ae%97%e7%ac%a6%e9%87%8d%e8%bd%bd","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/398.html","title":{"rendered":"Delphi\u7684\u8fd0\u7b97\u7b26\u91cd\u8f7d"},"content":{"rendered":"<p>\u4f7f\u7528Delphi\u7f16\u5199\u6e38\u620f\uff0c\u552f\u4e00\u6ca1\u6709C++\u65b9\u4fbf\u7684\u5c31\u662f\u4e0d\u652f\u6301\u8fd0\u7b97\u7b26\u91cd\u8f7d\u3002\u5f53\u4f60\u7f16\u5199\u6709\u5173\u5411\u91cf\u6216\u8005\u77e9\u9635\u8ba1\u7b97\u7684\u7a0b\u5e8f\u65f6\uff0c\u4e0d\u652f\u6301\u8fd0\u7b97\u7b26\u91cd\u8f7d\u7684Delphi\u4f7f\u7528\u8d77\u6765\u662f\u5f88\u8d39\u52b2\u7684\u3002<br \/>\n\u4f46\u662fDelphi 2006\u6539\u53d8\u4e86\u8fd9\u79cd\u5c40\u9762\uff0c\u65b0\u7684Delphi\u5185\u6838\u5df2\u7ecf\u652f\u6301\u8fd0\u7b97\u7b26\u91cd\u8f7d\u4e86\uff01<br \/>\n\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Delphi\u7684\u8fd0\u7b97\u7b26\u91cd\u8f7d\u529f\u80fd<br \/>\n\u6ce8\u610f\uff1a\u53ea\u6709Delphi 2006 \u548c \u514d\u8d39\u7248\u7684 Turbo Delphi \u652f\u6301\u8fd9\u4e00\u529f\u80fd\uff01<\/p>\n<p>Delphi for Win32 \u53ea\u652f\u6301 record \u7c7b\u578b\u7684\u8fd0\u7b97\u7b26\u91cd\u8f7d\uff0c\u800c Delphi .NET \u8fd8\u652f\u6301 class \u7c7b\u578b\u7684\u8fd0\u7b97\u7b26\u91cd\u8f7d<br \/>\n\u4e0b\u9762\u662fDelphi\u652f\u6301\u7684\u53ef\u91cd\u8f7d\u8fd0\u7b97\u7b26<br \/>\n\u8fd0\u7b97\u7b26 \u7c7b\u578b \u58f0\u660e\u8bed\u6cd5 \u5e94\u7528\u7b26\u53f7<br \/>\nImplicit \u8f6c\u6362 Implicit(a: type): resultType; \u9690\u5f0f\u8f6c\u6362<\/p>\n<p>Explicit \u8f6c\u6362 Explicit(a: type): resultType; \u663e\u5f0f\u8f6c\u6362<\/p>\n<p>\u8d1f \u4e00\u5143\u8fd0\u7b97 Negative(a: type): resultType; &#8211;<\/p>\n<p>\u6b63 \u4e00\u5143\u8fd0\u7b97 Positive(a: type): resultType; +<\/p>\n<p>\u9012\u589e \u4e00\u5143\u8fd0\u7b97 Inc(a: type): resultType; Inc<\/p>\n<p>\u9012\u51cf \u4e00\u5143\u8fd0\u7b97 Dec(a: type): resultType; Dec<\/p>\n<p>\u903b\u8f91\u975e \u4e00\u5143\u8fd0\u7b97 LogicalNot(a: type): resultType; not<\/p>\n<p>\u6309\u4f4d\u975e \u4e00\u5143\u8fd0\u7b97 BitwiseNot(a: type): resultType; not<\/p>\n<p>\u622a\u53d6 \u4e00\u5143\u8fd0\u7b97 Trunc(a: type): resultType; Trunc<\/p>\n<p>\u820d\u5165 \u4e00\u5143\u8fd0\u7b97 Round(a: type): resultType; Round<\/p>\n<p>\u7b49\u4e8e \u6bd4\u8f83 Equal(a: type; b: type) : Boolean; =<\/p>\n<p>\u4e0d\u7b49\u4e8e \u6bd4\u8f83 NotEqual(a: type; b: type): Boolean; &lt;&gt;<\/p>\n<p>\u5927\u4e8e \u6bd4\u8f83 GreaterThan(a: type; b: type) Boolean; &gt;<\/p>\n<p>\u5927\u4e8e\u7b49\u4e8e \u6bd4\u8f83 GreaterThanOrEqual(a: type; b: type): resultType; &gt;=<\/p>\n<p>\u5c0f\u4e8e \u6bd4\u8f83 LessThan(a: type; b: type): resultType; &lt;<\/p>\n<p>\u5c0f\u4e8e\u7b49\u4e8e \u6bd4\u8f83 LessThanOrEqual(a: type; b: type): resultType;<\/p>\n<p>\u52a0 \u4e8c\u5143\u8fd0\u7b97 Add(a: type; b: type): resultType; +<\/p>\n<p>\u51cf \u4e8c\u5143\u8fd0\u7b97 Subtract(a: type; b: type): resultType; &#8211;<\/p>\n<p>\u4e58 \u4e8c\u5143\u8fd0\u7b97 Multiply(a: type; b: type): resultType; *<\/p>\n<p>\u9664 \u4e8c\u5143\u8fd0\u7b97 Divide(a: type; b: type): resultType; \/<\/p>\n<p>\u6574\u9664 \u4e8c\u5143\u8fd0\u7b97 IntDivide(a: type; b: type): resultType; div<\/p>\n<p>\u6a21 \u4e8c\u5143\u8fd0\u7b97 Modulus(a: type; b: type): resultType; mod<\/p>\n<p>\u5de6\u79fb \u4e8c\u5143\u8fd0\u7b97 ShiftLeft(a: type; b: type): resultType; shl<\/p>\n<p>\u53f3\u79fb \u4e8c\u5143\u8fd0\u7b97 ShiftRight(a: type; b: type): resultType; shr<\/p>\n<p>\u903b\u8f91\u4e0e \u4e8c\u5143\u8fd0\u7b97 LogicalAnd(a: type; b: type): resultType; and<\/p>\n<p>\u903b\u8f91\u6216 \u4e8c\u5143\u8fd0\u7b97 LogicalOr(a: type; b: type): resultType; or<\/p>\n<p>\u903b\u8f91\u5f02\u6216 \u4e8c\u5143\u8fd0\u7b97 LogicalXor(a: type; b: type): resultType; xor<\/p>\n<p>\u6309\u4f4d\u4e0e \u4e8c\u5143\u8fd0\u7b97 BitwiseAnd(a: type; b: type): resultType; and<\/p>\n<p>\u6309\u4f4d\u6216 \u4e8c\u5143\u8fd0\u7b97 BitwiseOr(a: type; b: type): resultType; or<\/p>\n<p>\u6309\u4f4d\u5f02\u6216 \u4e8c\u5143\u8fd0\u7b97 BitwiseXor(a: type; b: type): resultType; xor<\/p>\n<p>\u5728\u5177\u4f53\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd0\u7b97\u7b26\u91cd\u8f7d\u524d\uff0c\u6211\u5148\u8bf4\u8bf4Delphi\u91ccrecord\u7684\u65b0\u529f\u80fd\u3002<br \/>\nDelphi2006 \u91cc\uff0crecord\u5df2\u7ecf\u548cclass \u5f88\u7c7b\u4f3c\u4e86\uff0c\u4f8b\u5982<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\ntype\r\n   TMyRecord = record\r\n   private\r\n     x : Integer;\r\n   public\r\n     constructor Create(val : Integer);\r\n     procedure Change(arg : integer); overload;\r\n     procedure Change(arg1, arg2 : Integer);overload;\r\n   end;\r\n<\/pre>\n<p>record\u548cclass\u7684\u533a\u522b\u662f<br \/>\nrecord \u4e0d\u652f\u6301\u7ee7\u627f<br \/>\nrecord \u5305\u542b\u53ef\u53d8\u90e8\u5206\uff1bclass\u6ca1\u6709\uff08\u5173\u4e8e\u53ef\u53d8\u90e8\u5206\uff0c\u8bf7\u53c2\u8003Delphi2006\u7684\u5e2e\u52a9\u6587\u4ef6\uff09<br \/>\nrecord \u662f\u503c\u7c7b\u578b\uff1bclass\u662f\u5f15\u7528\u7c7b\u578b\uff08\u5177\u4f53\u7684\u60c5\u51b5\uff0c\u540c\u6837\u8bf7\u53c2\u8003Delphi2006\u7684\u5e2e\u52a9\u6587\u4ef6\uff09<br \/>\nrecord \u5141\u8bb8\u5728Win32 \u548c .Net\u5e73\u53f0\u90fd\u652f\u6301\u8fd0\u7b97\u7b26\u91cd\u8f7d\uff1bclass\u53ea\u5728.NET\u91cc\u652f\u6301<br \/>\nrecord \u662f\u81ea\u52a8\u6784\u9020\u7684\uff0c\u4f7f\u7528\u7684\u662f\u9ed8\u8ba4\u7684\u65e0\u53c2\u6570\u6784\u9020\u51fd\u6570\uff0cclass\u5fc5\u987b\u663e\u5f0f\u6784\u9020\uff1b\u7531\u4e8erecord\u62e5\u6709\u9ed8\u8ba4\u7684\u65e0\u53c2\u6570\u6784\u9020\u51fd\u6570\uff0c\u6240\u4ee5\u7528\u6237\u5b9a\u4e49\u7684\u6784\u9020\u51fd\u6570\u81f3\u5c11\u8981\u6709\u4e00\u4e2a\u53c2\u6570<br \/>\nrecord \u6ca1\u6709\u6790\u6784\u51fd\u6570<br \/>\nrecord \u4e0d\u652f\u6301\u865a\u65b9\u6cd5<br \/>\nrecord \u5728Win32\u91cc\u4e0d\u652f\u6301interface\u7684\u5b9e\u73b0\uff0c\u5728.NET\u91cc\u53ef\u4ee5\u652f\u6301<\/p>\n<p>\u597d\u4e86\uff0c\u8be5\u770b\u770b\u8fd0\u7b97\u7b26\u91cd\u8f7d\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u4e86<br \/>\n\u9996\u5148\u662f\u5b9a\u4e49\uff0c\u53e5\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\ntype\r\n    typeName = &#x5B;class | record] \/\/\u53ea\u6709\u4f7f\u7528.NET\u65f6\uff0c\u624d\u80fd\u7528class\r\n        class operator conversionOp(a: type): resultType;\r\n        class operator unaryOp(a: type): resultType;\r\n        class operator comparisonOp(a: type; b: type): Boolean;\r\n        class operator binaryOp(a: type; b: type): resultType;\r\n    end;\r\n<\/pre>\n<p>\u5b9e\u73b0\u90e8\u5206\u7684\u53e5\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nclass operator typeName.conversionOp(a: type): resultType;\r\nclass operator typeName.unaryOp(a: type): resultType;\r\nclass operator typeName.comparisonOp(a: type; b: type): Boolean;\r\nclass operator typeName.binaryOp(a: type; b: type): resultType;\r\n<\/pre>\n<p>\u8fd8\u662f\u770b\u770b\u5177\u4f53\u7684\u4f8b\u5b50\u5427<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\ntype\r\n   TVector = record\r\n     x : Single;\r\n     y : Single;\r\n     z : Single;\r\n   public\r\n     constructor Create(x1, y1, z1); \/\/\u8fd9\u4e2a\u6784\u9020\u51fd\u6570\u53ef\u4ee5\u4e0d\u7528\u5199\uff0c\u539f\u56e0\u7a0d\u540e\u544a\u77e5\r\n     class operator Add(V1, V2 : TVector): TVector;            \/\/\u91cd\u8f7d\u8fd0\u7b97\u7b26 +\r\n     class operator Implicit(i : Single): TVector; overload;   \/\/\u9690\u5f0f\u8f6c\u6362\r\n     class operator Implicit(i : TVector): TVector; overload; \/\/\u540c\u4e0a\r\n   end;\r\n\r\n\/\/\u5177\u4f53\u7684\u5b9e\u73b0\r\n{ TVector }\r\n\r\nconstructor TVector.Create(x1, y1, z1: Single);\r\nbegin\r\n   x := x1;\r\n   y := y1;\r\n   z := z1;\r\nend;\r\n\r\nclass operator TVector.Add(V1, V2: TVector): TVector;\r\nbegin\r\n   Result.x := v1.x + v2.x;\r\n   Result.y := v1.y + v2.y;\r\n   Result.z := v1.z + v2.z;\r\n   Result.w := v1.w + v2.w;\r\nend;\r\n\r\nclass operator TVector.Implicit(i: Single): TVector;\r\nbegin\r\n   Result.x := i;\r\n   Result.y := i;\r\n   Result.z := i;\r\n   Result.w := i;\r\nend;\r\n\r\nclass operator TVector.Implicit(i: TVector): TVector;\r\nbegin\r\n   Result.x := i.x;\r\n   Result.y := i.y;\r\n   Result.z := i.z;\r\n   Result.w := i.w;\r\nend;\r\n\r\n\/\/\u8c03\u7528\u65b9\u6cd5\r\n...\r\nvar\r\n   v1, v2 : TVector;\r\nbegin\r\n...\r\n   v1.Create(1, 2, 3);\r\n\/\/\u4e5f\u53ef\u4ee5\u7528\u5982\u4e0b\u7684\u65b9\u6cd5\u7ed9x,y,z\u8d4b\u503c\r\n\/\/   v1.x := 1;\r\n\/\/   v1.y := 2;\r\n\/\/   v1.z := 3;\r\n\/\/\u6240\u4ee5\u8bf4\u521a\u624d\u7684Create\u51fd\u6570\u53ef\u4ee5\u4e0d\u8981\r\n\/\/\u548cclass\u4e0d\u540c\uff0crecord\u53ef\u4ee5\u81ea\u52a8\u7ed9\u6210\u5458\u521d\u59cb\u5316\r\n\/\/\u8fd9\u4e2a\u4f8b\u5b50\u91cc\uff0cx,y,z\u7684\u521d\u59cb\u5316\u503c\u4e3a 0\r\n\r\n   v2 := 1;   \/\/\u8c03\u7528\u4e86class operator Implicit(i : TVector): TVector\r\n             \/\/\u8fd9\u65f6v2\u6240\u6709\u6210\u5458\u90fd\u88ab\u8d4b\u503c\u62101\r\n   v2 := v1; \/\/\u8c03\u7528\u4e86class operator Implicit(i : TVector): TVector\r\n\r\n   v2 := v1 + v2; \/\/\u8c03\u7528\u4e86class operator Add(V1, V2 : TVector): TVector;\r\n\r\n   v2 := v2 + 1;   \/\/   class operator Add(V1, V2 : TVector): TVector\r\n                  \/\/\u548cclass operator Implicit(i : TVector): TVector\u7684\u590d\u5408\u8c03\u7528\r\n\r\nend;\r\n<\/pre>\n<p>Delphi\u7684\u8fd9\u79cd\u5b9e\u73b0\u65b9\u5f0f\u663e\u7136\u6bd4C++\u8981\u65b9\u4fbf\uff0c\u56e0\u4e3a\u4f60\u4e0d\u7528\u8003\u8651\u5185\u5b58\u91ca\u653e\uff1b\u4e5f\u53ef\u4ee5\u4e0d\u7528\u5b9a\u4e49\u6784\u9020\u51fd\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Delphi\u7f16\u5199\u6e38\u620f\uff0c\u552f\u4e00\u6ca1\u6709C++\u65b9\u4fbf\u7684\u5c31\u662f\u4e0d\u652f\u6301\u8fd0\u7b97\u7b26\u91cd\u8f7d\u3002\u5f53\u4f60\u7f16\u5199\u6709\u5173\u5411\u91cf\u6216\u8005\u77e9\u9635\u8ba1\u7b97\u7684\u7a0b\u5e8f\u65f6\uff0c\u4e0d\u652f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":4760,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/398\/revisions\/4760"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}