{"id":5697,"date":"2023-08-09T22:40:15","date_gmt":"2023-08-09T14:40:15","guid":{"rendered":"https:\/\/blog.qdac.cc\/?p=5697"},"modified":"2023-09-07T11:00:45","modified_gmt":"2023-09-07T03:00:45","slug":"%e6%95%99%e7%a8%8b%e4%bd%bf%e7%94%a8-zvaluewatch-%e5%9c%a8%e4%b8%bb%e7%ba%bf%e7%a8%8b%e4%b8%ad%e7%9b%91%e6%b5%8b%e5%80%bc%e5%8f%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=5697","title":{"rendered":"[\u6559\u7a0b] ZValueWatch \u6559\u7a0b\u4e4b\u4e00\uff1a\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u76d1\u6d4b\u503c\u53d8\u5316"},"content":{"rendered":"\n<p>Z \u7cfb\u5217\u53c8\u52a0\u5165\u4e86\u65b0\u7684\u6210\u5458\uff1aZValueWatch\uff0c\u5b83\u88ab\u5b9e\u73b0\u7528\u6765\u5f02\u6b65\u76d1\u6d4b\u4e00\u4e2a\u503c\u7684\u53d8\u5316\u3002<\/p>\n\n\n\n<p>IZValueWatch \u901a\u8fc7\u5c06\u8d4b\u503c\u548c\u53d8\u66f4\u901a\u77e5\u8fdb\u884c\u4e86\u5f02\u6b65\u5316\uff0c\u8fd9\u6837\u5b50\uff0c\u5728\u503c\u9891\u7e41\u53d8\u5316\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u6709\u6548\u7684\u51cf\u5c11\u53d8\u66f4\u901a\u77e5\u7684\u6b21\u6570\uff0c\u4ece\u800c\u63d0\u5347\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5047\u8bbe\u4e00\u4e2a\u5178\u578b\u7684\u5e94\u7528\u573a\u666f\uff1a\u6211\u4eec\u5728\u540e\u53f0\u7ebf\u7a0b\u4e2d\u8981\u6267\u884c\u957f\u65f6\u95f4\u7684\u64cd\u4f5c\uff0c\u5e76\u4e14\u53ca\u65f6\u66f4\u65b0\u524d\u53f0\u7684\u8fdb\u5ea6\u663e\u793a\u3002\u5728\u4e00\u822c\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e3a\u4e86\u663e\u793a\u8fdb\u5ea6\uff0c\u4f7f\u7528 TThread.Queue\/Synchronize \u6765\u8ba9\u7a0b\u5e8f\u66f4\u65b0\u4e3b\u754c\u9762\u7684\u8fdb\u5ea6\u663e\u793a\uff0c\u5982\u679c\u6211\u4eec\u9891\u7e41\u66f4\u65b0\u8fdb\u5ea6\u4fe1\u606f\uff0c\u5c31\u4f1a\u9891\u7e41\u7684\u5728\u540e\u53f0\u7ebf\u7a0b\u548c\u4e3b\u7ebf\u7a0b\u4e2d\u8fdb\u884c\u5207\u6362\uff0c\u5f71\u54cd\u540e\u53f0\u7ebf\u7a0b\u7684\u6267\u884c\u6548\u7387\u3002\u800c\u5b9e\u9645\u4e0a\uff0c\u8fdb\u5ea6\u7684\u4e2d\u95f4\u663e\u793a\u5185\u5bb9\u662f\u53ef\u5ffd\u7565\u7684\u5185\u5bb9\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4fdd\u8bc1\u5176\u503c\u5728\u754c\u9762\u6e32\u67d3\u65f6\uff0c\u80fd\u591f\u8bfb\u53d6\u5230\u6700\u65b0\u7684\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>ZValueWatch \u5b9e\u73b0\u4e86\u8fd9\u4e00\u673a\u5236\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u540e\u53f0\u64cd\u4f5c\u65f6\uff0c\u968f\u65f6\u66f4\u65b0\u8fdb\u5ea6\uff0c\u800c\u8fd9\u4e2a\u8fdb\u5ea6\u7684\u66f4\u65b0\u5e76\u4e0d\u4f1a\u7acb\u5373\u53cd\u9988\u5230\u4e3b\u754c\u9762\uff0c\u800c\u662f\u4f1a\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u68c0\u67e5\u8fd9\u4e00\u53d8\u52a8\uff0c\u7136\u540e\u5c06\u5176\u5448\u73b0\u7ed9\u7528\u6237\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u73b0\u5728\u6309\u987a\u5e8f\u6765\u5b9e\u73b0\u8fd9\u4e00\u4e2a\u529f\u80fd\uff1a<\/p>\n\n\n\n<p>1\u3001\u5b9a\u4e49\u4e00\u4e2a\u8fdb\u5ea6\u63d0\u793a\u7684\u8bb0\u5f55\u7c7b\u578b\uff0c\u7528\u4e8e\u7f13\u5b58\u8fdb\u5ea6\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type\n  TProgressHint = record\n    Progress: Integer;\n    Hint: String;\n  end;<\/code><\/pre>\n\n\n\n<p>2\u3001\u6211\u4eec\u5728\u7a97\u4f53\u6dfb\u52a0\u9700\u8981\u7684\u63a7\u4ef6\uff0c\u7136\u540e\u5b9a\u4e49\u7684\u79c1\u6709\u90e8\u5206\uff0c\u58f0\u660e\u4e00\u4e2a\u8fdb\u5ea6\u53d8\u66f4\u76d1\u89c6\u53d8\u91cf FProgressWatch\uff0c\u4e3a\u4e86\u4fbf\u4e8e\u89c2\u5bdf\uff0c\u6211\u4eec\u989d\u5916\u589e\u52a0\u4e00\u4e2a FInvokeTimes \u6765\u8bb0\u5f55\u76d1\u89c6\u53d8\u91cf\u53d8\u66f4\u4e8b\u4ef6\u89e6\u53d1\u7684\u6b21\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> TForm1 = class(TForm)   \n  ...\n  private\n    { Private declarations }\n    <strong>FInvokeTimes: Integer;<\/strong>\n    <strong>FProgressWatch: IZValueWatch&lt;TProgressHint&gt;;<\/strong>\n  public\n    { Public declarations }\n  end;<\/code><\/pre>\n\n\n\n<p>3\u3001\u53cc\u51fb\u7a97\u4f53\uff0c\u5728\u5176 OnCreate \u4e8b\u4ef6\u54cd\u5e94\u4e2d\uff0c\u5b9a\u4e49\u8fd9\u4e2a\u53d8\u91cf\u53ca\u5176\u503c\u53d8\u66f4\u65f6\u7684\u54cd\u5e94\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>procedure TForm1.FormCreate(Sender: TObject);\nbegin\n  FProgressWatch := TZWatchItems.Current.CreateWatch&lt;TProgressHint&gt;(\n    procedure(const AValue: TProgressHint)\n    begin\n      Inc(FInvokeTimes);\n      ProgressBar1.Position := AValue.Progress;\n      Label1.Caption := AValue.Hint;\n      Label1.Update;\n      if AValue.Progress = 100 then\n      begin\n        Button1.Caption := 'Start Progress';\n        Button1.Enabled := true;\n        Memo1.Lines.Add(FormatDateTime('hh:nn:ss.zzz', Now) +\n          ' Watch change monitor times:' + FInvokeTimes.ToString);\n      end;\n    end);\nend;<\/code><\/pre>\n\n\n\n<p>4\u3001\u53cc\u51fb\u7a97\u4f53\u7684 Start Progress \u6309\u94ae\uff0c\u5728\u5176 OnClick \u4e8b\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u7ebf\u7a0b\uff0c\u6765\u5faa\u73af1000\u4e07\u6b21<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>procedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Button1.Caption := 'Processing...';\n  Button1.Enabled := false;\n  FInvokeTimes := 0;\n  Memo1.Lines.Add(FormatDateTime('hh:nn:ss.zzz', Now) + ' Start process ...');\n  TThread.CreateAnonymousThread(\n    procedure\n    var\n      AProgress: TProgressHint;\n      ACount: Integer;\n      ATime: Cardinal;\n    const\n      PassCount = 10000000;\n    begin\n      ACount := 0;\n      ATime := TThread.GetTickCount;\n      while (not Application.Terminated) and (ACount &lt; PassCount) do\n      begin\n        AProgress.Progress := ACount * 100 div PassCount;\n        AProgress.Hint := ACount.ToString;\n        Inc(ACount);\n        <strong>FProgressWatch.Value := AProgress;<\/strong>\n      end;\n      AProgress.Hint := (TThread.GetTickCount - ATime).ToString + 'ms';\n      AProgress.Progress := 100;\n      <strong>FProgressWatch.Value := AProgress;<\/strong>\n    end).Start;\nend;<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u6211\u4eec\u4e0a\u9762\u7684\u5199\u6cd5\uff0c\u7ebf\u7a0b\u4e2d\u53ea\u4fee\u6539\u5c40\u90e8\u53d8\u91cf\u7684\u503c\uff0c\u5728\u66f4\u65b0\u5b8c\u6210\u540e\uff0c\u4e00\u6b21\u6027\u8d4b\u503c\u7ed9 FProgressWatch.Value\u3002\u8fd9\u91cc\u662f\u56e0\u4e3a\u6211\u4eec\u7684 Value \u662f\u4e00\u4e2a\u6574\u4f53\uff0c\u662f\u901a\u8fc7 GetValue \u51fd\u6570\u8fd4\u56de\u7684\u4e34\u65f6\u53d8\u91cf\uff0c\u5199\u6210 FProgressWatch.Value.Progress := \u503c \u7684\u5f62\u5f0f\u5bf9 FProgressWatch.Value \u7684\u503c\uff0c\u4e0d\u4f1a\u4ea7\u751f\u4efb\u4f55\u5f71\u54cd\u3002<br>5\u3001\u73b0\u5728\u6211\u4eec\u8fd0\u884c\u7a0b\u5e8f\uff0c\u5e76\u70b9\u51fb Start Progress \u6309\u94ae\uff0c\u5c31\u4f1a\u770b\u5230\u8fdb\u5ea6\u6761\u548c\u63d0\u793a\u6587\u672c\u5728\u8ddf\u968f\u540e\u53f0\u7ebf\u7a0b\u5904\u7406\u7684\u8fdb\u5ea6\u5feb\u901f\u53d8\u5316\u3002<br><br>\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u8fd9\u4e2a\u5b9e\u73b0\u8981\u5206\u4e09\u6b65\u8d70\uff1a\u5b9a\u4e49\u89c2\u5bdf\u7684\u503c\u7c7b\u578b\uff0c\u521b\u5efa\u89c2\u5bdf\u63a5\u53e3\u5b9e\u4f8b\uff08TZWatchItems.Current.CreateWatch\uff09\u3001\u4fee\u6539\u89c2\u5bdf\u63a5\u53e3\u5b9e\u4f8b\u7684 Value \u503c\u3002<br><br><strong>\u3010\u6ce8\u610f\u3011<\/strong><\/p>\n\n\n\n<p>1\u3001\u8981\u68c0\u67e5\u503c\u7684\u53d8\u52a8\uff0c\u6211\u4eec\u9700\u8981\u8c03\u7528 TZWatchItems.CheckChanges \u51fd\u6570\uff0c\u9ed8\u8ba4\u5b9e\u73b0\u63d0\u4f9b\u4e86\u4e09\u79cd\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u624b\u52a8\u68c0\u67e5\uff08wkNone\uff09\uff1a\u7531\u7a0b\u5e8f\u5458\u81ea\u5df1\u53bb\u8d1f\u8d23\u89e6\u53d1\uff0c\u5982\u679c\u60a8<\/li>\n\n\n\n<li>\u5b9a\u65f6\u68c0\u67e5\uff08wkTimer\uff09\uff1a\u5f53\u6709\u9700\u8981\u76d1\u89c6\u7684\u5bf9\u8c61\u65f6\uff0c\u6bcf16ms\uff08\u76f8\u5f53\u4e8e 60 FPS\uff09\u4f1a\u81ea\u52a8\u68c0\u67e5\u4e00\u6b21\uff08\u9ed8\u8ba4\uff09<\/li>\n\n\n\n<li>\u6d88\u606f\u9a71\u52a8\uff08wkMessage\uff09\uff1a\u5f53\u76d1\u89c6\u7684\u5bf9\u8c61\u503c\u53d1\u751f\u53d8\u52a8\u65f6\uff0c\u4f1a\u5411\u4e3b\u7ebf\u7a0b\u6295\u9012 WM_NULL \u6d88\u606f\uff0c\u5e94\u7528\u4f1a\u5728 WM_NULL \u6d88\u606f\u7684\u5904\u7406\u91cc\uff0c\u89e6\u53d1 TZWatchItems.CheckChanges \u7684\u8c03\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<p>2\u3001TZWatchItems.CheckChanges \u5fc5\u9700\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c\uff0c\u540e\u53f0\u7ebf\u7a0b\u6267\u884c\u4f1a\u76f4\u63a5\u62a5\u9519\u3002<\/p>\n\n\n\n<p>3\u3001\u5982\u679c\u8981\u5728\u7ebf\u7a0b\u4e2d\u68c0\u67e5\u67d0\u4e2a\u503c\u7684\u53d8\u52a8\uff0c\u90a3\u4e48\u53ef\u4ee5\u8c03\u7528 CreateWatch \u8fd4\u56de\u7684\u63a5\u53e3\u5b9e\u4f8b\u7684 CheckChanged \u51fd\u6570\uff0c\u5982\u679c\u53d1\u751f\u53d8\u52a8\uff0c\u4f1a\u89e6\u53d1\u901a\u77e5\u56de\u8c03\u51fd\u6570\u3002CheckChanged \u672c\u8eab\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u4f46\u662f\u5728\u8fd9\u79cd\u4f7f\u7528\u573a\u666f\u4e0b\uff0c\u7528\u6237\u5e94\u8be5\u4fdd\u8bc1\u901a\u77e5\u56de\u8c03\u51fd\u6570\u91cc\u7684\u64cd\u4f5c\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u4e00\u822c\u6211\u4eec\u5e76\u4e0d\u63a8\u8350\u8fd9\u6837\u505a\uff0c\u8fd9\u6837\u505a\u5b9e\u9645\u4e0a\u8fdd\u80cc\u4e86\u6211\u4eec\u7684\u8bbe\u8ba1\u521d\u8877\u3002<\/p>\n\n\n\n<p>4\u3001\u63a8\u8350\u7528\u6237\u6839\u636e\u5b9e\u9645\u9700\u8981\uff0c\u8c03\u6574\u5b9a\u65f6\u68c0\u67e5\u7684\u95f4\u9694\u3002<\/p>\n\n\n\n<p>5\u3001\u6781\u9650\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u66f4\u65b0\u4e00\u4e2a\u503c\uff0c\u5219\u53ea\u6709\u7b2c\u4e00\u6b21\u66f4\u65b0\u7684\u503c\u4f1a\u88ab\u8bb0\u5f55\uff0c\u5176\u5b83\u503c\u4f1a\u88ab\u5ffd\u7565\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u65e0\u8bba\u662f\u7528\u6237\u8fd8\u662f\u7a0b\u5e8f\u672c\u8eab\uff0c\u5b9e\u9645\u4e0a\u90fd\u4e0d\u80fd\u51c6\u786e\u533a\u5206\u5e94\u8be5\u4fdd\u7559\u90a3\u4e2a\u503c\uff0c\u7a0b\u5e8f\u8fd9\u91cc\u4f1a\u68c0\u67e5  FUpdateRefCount \u662f\u5426\u4e3a 1\uff0c\u4e0d\u4e3a 1 \u7684\u503c\u4f1a\u88ab\u5ffd\u7565\u6389\u3002<\/p>\n\n\n\n<p><strong>\u3010\u66f4\u591a\u793a\u4f8b\u3011<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u8981\u66f4\u65b0\u67d0\u4e2a\u63a7\u4ef6\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\uff0c\u6309\u4e0a\u9762\u7684\u7684\u6b65\u9aa4\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4e0b\u9762\u7684\u4ee3\u7801\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5b9a\u4e49\u53d8\u91cf\nprivate\n   FControlBoundsWatch:IZValueWatch&lt;TRect&gt;;\n....\n\/\/\u521d\u59cb\u5316\nFControlBoundsWatch:=TZWatchItems.Current.CreateWatch&lt;TRect&gt;(\n  procedure (const R:TRect)\n  begin\n  Label1.SetBounds(R.Left,R.Top,R.Width,R.Height);\n  end);\n....\n\/\/\u8d4b\u503c \nFControBoundsWatch.Value:=Rect(100,20,300,40);<\/code><\/pre>\n\n\n\n<p><strong>\u3010\u4e0b\u8f7d\u3011<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2023\/08\/progresswatch.zip\">\u4e0b\u8f7d\u4e8c\u8fdb\u5236\u793a\u4f8b\u7a0b\u5e8f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Z \u7cfb\u5217\u53c8\u52a0\u5165\u4e86\u65b0\u7684\u6210\u5458\uff1aZValueW [&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,816],"tags":[200,818,217,63,118,817,312],"class_list":["post-5697","post","type-post","status-publish","format-standard","hentry","category-delphi","category-z","tag-200","tag-818","tag-217","tag-63","tag-118","tag-817","tag-312"],"views":2326,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5697","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=5697"}],"version-history":[{"count":8,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5697\/revisions"}],"predecessor-version":[{"id":5721,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/5697\/revisions\/5721"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}