{"id":5608,"date":"2022-09-17T12:14:48","date_gmt":"2022-09-17T04:14:48","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=5608"},"modified":"2022-09-22T10:16:04","modified_gmt":"2022-09-22T02:16:04","slug":"fmx%e8%bf%90%e8%a1%8c%e6%97%b6%e5%8a%a8%e6%80%81%e4%bf%ae%e6%94%b9%e6%a0%b7%e5%bc%8f%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=5608","title":{"rendered":"[FMX]\u6559\u7a0b\uff1a\u8fd0\u884c\u65f6\u52a8\u6001\u4fee\u6539 FMX \u6837\u5f0f"},"content":{"rendered":"\n<p>\u7b80\u5355\u8bf4\u51e0\u4e2a\u70b9\uff1a<\/p>\n\n\n\n<p>1\u3001FMX \u6846\u67b6\u4e0b\uff0c\u6837\u5f0f\u662f\u901a\u8fc7\u540d\u79f0\u6765\u6807\u5fd7\u7684\u3002<\/p>\n\n\n\n<p>2\u3001GetStyleObject \u9ed8\u8ba4\u662f\u514b\u9686\u539f\u59cb\u7684\u6837\u5f0f\uff0c\u6240\u4ee5\u76f4\u63a5\u4fee\u6539\u5bf9\u8c61\u81ea\u8eab\u7684 FResourceLink \u5b9e\u4f8b\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5176\u5b83\u6837\u5f0f\uff0c\u5982\u679c\u8981\u4fee\u6539\u5168\u90e8\u540c\u4e00\u7c7b\u578b\u63a7\u4ef6\u7684\u6837\u5f0f\uff0c\u624b\u52a8\u8c03\u7528\u63a7\u4ef6\u7684 GetStyleObject(false) \u6765\u83b7\u53d6\u6837\u5f0f\u7684\u539f\u59cb\u5b9e\u4f8b\u5373\u53ef\uff0c\u8fdb\u884c\u8c03\u6574\u5373\u53ef\u3002<\/p>\n\n\n\n<p>2\u3001\u53ea\u4fee\u6539\u5f53\u524d\u5b9e\u4f8b\u7684\u7279\u5b9a\u6837\u5f0f\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u901a\u8fc7 ResourceLink \u4fdd\u62a4\u5c5e\u6027\u83b7\u53d6\u5bf9\u5e94\u7684\u6837\u5f0f\u5bf9\u8c61\uff08\u53d7\u4fdd\u62a4\u6210\u5458\u5177\u4f53\u5982\u4f55\u8bbf\u95ee\u53c2\u8003\u4ee5\u524d\u7684\u6587\u7ae0\uff09<\/li><li>\u76f4\u63a5\u4fee\u6539\u5bf9\u5e94\u7684\u6837\u5f0f\u5bf9\u8c61\u6216\u8005\u4ece ResourceLink \u4e2d\u5220\u9664\u5b83\uff0c\u7136\u540e\u518d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 StyleName \u540c\u540d\u7684\u5bf9\u8c61\uff0c\u6dfb\u52a0\u5230 ResourceLink \u4e2d<\/li><li>\u8c03\u7528 ApplyStyle \u4fdd\u62a4\u65b9\u6cd5\uff0c\u6765\u5e94\u7528\u6837\u5f0f<\/li><\/ul>\n\n\n\n<p>3\u3001\u4fee\u6539\u5168\u5c40\u6837\u5f0f\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u901a\u8fc7 GetStyleObject \u4fdd\u62a4\u65b9\u6cd5\uff0c\u83b7\u53d6\u539f\u59cb\u7684\u5bf9\u8c61\u94fe\u63a5\u3002<\/li><li>\u67e5\u627e\u5bf9\u5e94\u7684\u6837\u5f0f\u5bf9\u8c61\u5b9e\u4f8b<\/li><li>\u89c6\u9700\u8981\u76f4\u63a5\u4fee\u6539\u5bf9\u5e94\u7684\u6837\u5f0f\u5bf9\u8c61\u6216\u8005\u4ece ResourceLink \u4e2d\u5220\u9664\u5b83\uff0c\u7136\u540e\u518d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 StyleName \u540c\u540d\u7684\u5bf9\u8c61\uff0c\u6dfb\u52a0\u5230 ResourceLink \u4e2d<\/li><li>\u53d1\u9001 TStyleChangedMessage \u6d88\u606f\uff0c\u8fd9\u6837\u6240\u6709\u7684\u63a7\u4ef6\u90fd\u4f1a\u66f4\u65b0\u6837\u5f0f\u3002\u5982\u679c\u53ea\u662f\u5f53\u524d\u63a7\u4ef6\uff0c\u90a3\u4e48\u8c03\u7528\u4e0bNeedStyleLookup \u5373\u53ef\u3002<\/li><\/ul>\n\n\n\n<p>\u53c2\u8003\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uses syste\nm.Messaging;\n{$R *.fmx}\ntype\nTHackedListView=class(TListView)\n\nend;\nprocedure TForm4.ComboColorBox1Change(Sender: TObject);\nvar\n  AStyle,AStyleLink:TFMXObject;\nbegin\n\/\/ \u4ec5\u4fee\u6539 ListView1 \u7684\u6837\u5f0f\n\/\/  AStyleLink:=THackedListView(ListView1).ResourceLink;\n\/\/ \u4fee\u6539\u5168\u5c40\u7684 TListView \u6837\u5f0f\n  AStyleLink:= THackedListView(ListView1).GetStyleObject(false);\n  AStyle:=AStyleLink.FindStyleResource('selection');\n  if Assigned(AStyle) then\n  begin\n    if not (AStyle is TColorObject) then\n      begin\n      AStyleLink.RemoveObject(AStyle);\n      AStyle:=TColorObject.Create(AStyleLink);\n      AStyle.StyleName:='selection';\n      AStyleLink.AddObject(AStyle);\n      end;\n      (AStyle as TColorObject).Color:=ComboColorBox1.Color;  \n\/\/\u4ec5\u4fee\u6539 ListView1 \u7684\u6837\u5f0f\n\/\/  THackedListView(ListView1).ApplyStyle;\n\/\/ \u4fee\u6539\u4e86\u5168\u5c40\u6837\u5f0f\uff0c\u4f46\u5f53\u524d\u53ea\u5e94\u7528 ListView1\n\/\/  ListView1.NeedStyleLookup;\n\/\/ \u4fee\u6539\u4e86\u5168\u5c40\u6837\u5f0f\uff0c\u5176\u5b83\u6240\u6709 ListView \u90fd\u66f4\u65b0\n      TMessageManager.DefaultManager.SendMessage(Sender,TStyleChangedMessage.Create(StyleBook));\n\n  end;\nend;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2022\/09\/\u5f55\u5c4f_\u9009\u62e9\u533a\u57df_20220917113911.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"510\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2022\/09\/\u5f55\u5c4f_\u9009\u62e9\u533a\u57df_20220917113911.gif\" alt=\"\" class=\"wp-image-5609\"\/><\/a><\/figure>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5728 Windows \u4e0b\u662f\u6ca1\u6709\u95ee\u9898\u7684\uff0c\u5728\u5176\u5b83\u5e73\u53f0\uff0c\u7531\u4e8e\u5728\u514b\u9686\u6837\u5f0f\u65f6\uff0cFMX \u91c7\u7528\u4e86\u4e0d\u540c\u7684\u7b56\u7565\uff0c\u6240\u4ee5\u9700\u8981\u505a\u53d8\u52a8\uff0c\u53c2\u8003\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type\n  THackedListView = class(TListView)\n\n  end;\n\nprocedure ChangeListViewSelectionColor(AListView: TListView; ANewColor: TAlphaColor); overload;\nvar\n  AStyle, AStyleLink: TFmxObject;\nbegin\n  AStyleLink := THackedListView(AListView).ResourceLink;\n  AStyle := AStyleLink.FindStyleResource('selection');\n  if Assigned(AStyle) then\n  begin\n    if not(AStyle is TColorObject) then\n    begin\n      AStyleLink.RemoveObject(AStyle);\n      AStyle := TColorObject.Create(AStyleLink);\n      AStyle.StyleName := 'selection';\n      AStyleLink.AddObject(AStyle);\n    end;\n    (AStyle as TColorObject).Color := ANewColor;\n    THackedListView(AListView).ApplyStyle;\n  end;\nend;\n\nprocedure ChangeListViewSelectionColor(ANewColor: TAlphaColor); overload;\nvar\n  I: Integer;\n  procedure ApplyColor(AParent: TFmxObject);\n  var\n    AIndex: Integer;\n  begin\n    if AParent is TListView then\n      ChangeListViewSelectionColor(TListView(AParent),ANewColor);\n    for AIndex := 0 to AParent.ChildrenCount - 1 do\n      ApplyColor(AParent.Children&#91;AIndex]);\n  end;\n\nbegin\n  for I := 0 to Screen.FormCount - 1 do\n    ApplyColor(Screen.Forms&#91;I]);\nend;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5355\u8bf4\u51e0\u4e2a\u70b9\uff1a 1\u3001FMX \u6846\u67b6\u4e0b\uff0c\u6837\u5f0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","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,603],"tags":[149,321],"class_list":["post-5608","post","type-post","status-publish","format-standard","hentry","category-delphi","category-603","tag-fmx","tag-321"],"views":3095,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5608","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=5608"}],"version-history":[{"count":4,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5608\/revisions"}],"predecessor-version":[{"id":5613,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5608\/revisions\/5613"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}