{"id":2102,"date":"2015-03-10T09:56:36","date_gmt":"2015-03-10T01:56:36","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=2102"},"modified":"2015-03-10T09:56:36","modified_gmt":"2015-03-10T01:56:36","slug":"%e9%80%9a%e8%bf%87-tqdataset-oncustomsort-%e5%b1%9e%e6%80%a7%e6%9d%a5%e6%8c%89%e6%8b%bc%e9%9f%b3%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=2102","title":{"rendered":"\u901a\u8fc7 TQDataSet.OnCustomSort \u5c5e\u6027\u6765\u6309\u62fc\u97f3\u6392\u5e8f"},"content":{"rendered":"<p>TQDataSet \u65b0\u63d0\u4f9b\u4e86\u4e00\u4e2a OnCustomSort \u5c5e\u6027\uff0c\u7528\u4e8e\u8ba9\u7528\u6237\u6307\u5b9a\u81ea\u5df1\u7684\u6392\u5e8f\u89c4\u5219\u3002\u5982\u679c\u8bbe\u7f6e\u4e86 OnCustomSort \u4e8b\u4ef6\u7684\u503c\uff0c\u5219 TQDataSet \u4f1a\u8c03\u7528 OnCustomSort \u4e8b\u4ef6\u6765\u83b7\u53d6\u4e24\u6761\u8bb0\u5f55\u7684\u6bd4\u8f83\u7ed3\u679c\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5728 Windows \u4e0b\u6309\u62fc\u97f3\u6392\u5e8f\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">\/\/\u6309\u62fc\u97f3\u6bd4\u8f83\u4e24\u6761\u8bb0\u5f55\u7684\u5927\u5c0f\r\nprocedure TForm1.DoSortBySpell(ADataSet: TQDataSet;\r\n  ARecord1, ARecord2: TQRecord; var AResult: Integer);\r\nbegin\r\nAResult := CompareStringW(\r\n  \/\/ \u6309\u6c49\u8bed\u62fc\u97f3\u6392\u5e8f\r\n  MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED),\r\n  SORT_CHINESE_PRCP), NORM_IGNORECASE or NORM_IGNOREWIDTH,\r\n  PWideChar(ARecord1.Values[2].CurrentValue.AsString), -1,\r\n  PWideChar(ARecord2.Values[2].CurrentValue.AsString), -1) - CSTR_EQUAL;\r\nend;\r\n\r\nprocedure TForm1.Button2Click(Sender: TObject);\r\nbegin\r\nif Assigned(FDataSet.OnCustomSort) then\/\/\u5982\u679c\u5df2\u7ecf\u6307\u5b9a\u4e86\u81ea\u5b9a\u4e49\u6392\u5e8f\uff0c\u5219\u5173\u95ed\u81ea\u5b9a\u4e49\u6392\u5e8f\r\n  FDataSet.OnCustomSort := nil\r\nelse\/\/\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u6392\u5e8f\u6bd4\u8f83\u89c4\u5219\r\n  FDataSet.OnCustomSort := DoSortBySpell;\r\nend;<\/pre>\n<p>\u5728 DoSortBySpell \u4e2d\uff0c\u8bb0\u5f55\u7684 Values[2] \u5bf9\u5e94\u7684\u662f Name \u5b57\u6bb5\uff0c\u4e5f\u5c31\u662f\u8bf4\u5c06\u6570\u636e\u96c6\u7684 Name \u5b57\u6bb5\u7684\u62fc\u97f3\u987a\u5e8f\u3002\u6548\u679c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/QDataSet_PY.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2103\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/QDataSet_PY.jpg\" alt=\"QDataSet_PY\" width=\"759\" height=\"575\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/QDataSet_PY.jpg 759w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/QDataSet_PY-300x227.jpg 300w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TQDataSet \u65b0\u63d0\u4f9b\u4e86\u4e00\u4e2a OnC [&hellip;]<\/p>\n","protected":false},"author":1,"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":[69,8,9,66,21],"tags":[16,17],"class_list":["post-2102","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-qdb","category-misc","tag-16","tag-17"],"views":3170,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2102","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2102"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2102\/revisions"}],"predecessor-version":[{"id":2104,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2102\/revisions\/2104"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}