{"id":24,"date":"2014-08-23T22:51:32","date_gmt":"2014-08-23T14:51:32","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=24"},"modified":"2014-08-27T22:13:40","modified_gmt":"2014-08-27T14:13:40","slug":"delphi%e9%9d%99%e6%80%81%e6%95%b0%e7%bb%84rtti%e4%bf%a1%e6%81%af%e7%a0%94%e7%a9%b6","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=24","title":{"rendered":"Delphi\u9759\u6001\u6570\u7ec4RTTI\u4fe1\u606f\u7814\u7a76"},"content":{"rendered":"<div class=\"d_post_content j_d_post_content \">\u4f5c\u8005\uff1aswish<\/div>\n<div class=\"d_post_content j_d_post_content \"><\/div>\n<div id=\"post_content_54367251284\" class=\"d_post_content j_d_post_content \">\u7b2c\u4e00\u3001\u8981\u77e5\u9053\u9759\u6001\u6570\u7ec4\u7c7b\u578b\u7684PTypeInfo\u7684\u7c7b\u578b\u4fe1\u606f\uff0c\u53ef\u4ee5\u901a\u8fc7TypeInfo(\u6570\u7ec4\u7c7b\u578b)\u6765\u83b7\u53d6\u5230\u3002<br \/>\n\u7b2c \u4e8c\u3001\u77e5\u9053\u4e0a\u8ff0\u7c7b\u578b\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7GetTypeData\u51fd\u6570\u6765\u83b7\u53d6\u5230\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u4fe1\u606f\uff0c\u901a\u8fc7ArrayData.ElCount\u5c31\u662f\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\uff0c \u901a\u8fc7PTypeData.ArrayData.ElType\u53d6\u5143\u7d20\u7684\u7c7b\u578b\u3002\u5982\u679cRTTI\u4fe1\u606f\u4e0d\u5b58\u5728\uff0c\u5219\u4e0d\u9700\u8981\u7ee7\u7eed\u4e86\uff0c\u4f60\u7684\u4ee3\u7801\u6ca1\u6709\u76f8\u5e94\u7c7b\u578b\u7684RTTI\u4fe1 \u606f\uff0c\u4f60\u5c1d\u8bd5\u5355\u72ec\u5c06\u9759\u6001\u6570\u7ec4\u7684\u7c7b\u578b\u62ff\u51fa\u6765\u5b9a\u4e49\u770b\u770b\u3002<br \/>\n\u7b2c\u4e09\u3001\u77e5\u9053\u4e86\u5b50\u5143\u7d20\u7684\u7c7b\u578b\u540e\uff0c\u5176TypeData\u7684ElSize\u5c31\u662f\u5355\u4e2a\u6570\u7ec4\u5143\u7d20\u7684\u5927\u5c0f\u5360\u7528\u7a7a\u95f4\u5927\u5c0f\uff0c\u8fd9\u4e2a\u6570\u7ec4\u7684\u7a7a\u95f4\u5360\u7528\u4e5f\u5c31\u597d\u7b97\u4e86\uff0c\u5c31\u662f\u5143\u7d20\u6570\u91cf*\u5355\u4e2a\u5143\u7d20\u7684\u7a7a\u95f4\u5360\u7528\u5927\u5c0f\u5c31OK\u4e86\u3002<br \/>\n\u7b2c\u56db\u3001\u4f60\u60f3\u548b\u6298\u817e\u4ffa\u5c31\u4e0d\u77e5\u9053\u4e86\u3002<br \/>\n\u53c2\u8003\u4ee3\u7801\u5728QJson\u4e2d\u6709\uff0c\u62bd\u53d6\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:delphi decode:true  \">function GetFixedArrayItemType:PTypeInfo;\r\nvar\r\n  pType:PPTypeInfo;\r\nbegin\r\n  pType:= GetTypeData(AType)^.ArrayData.ElType;\r\n  if pType = nil then\r\n  Result := nil\r\nelse\r\n  Result := pType^;\r\nend;\r\n\r\nprocedure ToFixedArray;\r\nvar\r\n  I,C,ASize:Integer;\r\n  ASubType:PTypeInfo;\r\n  AChild:TQJson;\r\n  AChildObj:TObject;\r\n  pi:Pointer;\r\nbegin\r\n  C:=GetTypeData(AType).ArrayData.ElCount;\r\n  ASubType:=GetFixedArrayItemType;\r\n  if ASubType=nil then\r\n    Exit;\r\n  ASize:=GetTypeData(ASubType).elSize;\r\n  for I := 0 to C-1 do\r\n    begin\r\n    pi:=Pointer(IntPtr(ADest)+ASize*I);\r\n    ...\r\n    end;\r\nend;<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"d_post_content j_d_post_content \"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1aswish \u7b2c\u4e00\u3001\u8981\u77e5\u9053\u9759\u6001\u6570\u7ec4\u7c7b [&hellip;]<\/p>\n","protected":false},"author":3,"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-24","post","type-post","status-publish","format-standard","hentry","category-delphi"],"views":4006,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/24","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":307,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/24\/revisions\/307"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}