{"id":2051,"date":"2015-02-25T01:13:32","date_gmt":"2015-02-24T17:13:32","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=2051"},"modified":"2015-02-25T01:13:32","modified_gmt":"2015-02-24T17:13:32","slug":"qworker-%e6%9b%b4%e6%96%b0-tqjobgroup-%e6%96%b0%e5%a2%9e-insert-%e5%87%bd%e6%95%b0%e6%9d%a5%e4%b8%b4%e6%97%b6%e6%8f%92%e5%85%a5%e4%b8%80%e4%b8%aa%e4%bd%9c%e4%b8%9a","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=2051","title":{"rendered":"QWorker \u66f4\u65b0 &#8211; TQJobGroup \u65b0\u589e Insert \u51fd\u6570\u6765\u4e34\u65f6\u63d2\u5165\u4e00\u4e2a\u4f5c\u4e1a"},"content":{"rendered":"<p>\u3010\u66f4\u65b0\u8bf4\u660e\u3011<\/p>\n<p>\u5982\u679c\u6211\u4eec\u5728\u987a\u5e8f\u4f5c\u4e1a\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u60f3\u8981\u4e34\u65f6\u5728\u4f5c\u4e1a\u4e2d\u63d2\u5165\u4e00\u4e2a\u4f5c\u4e1a\u65f6\uff0c\u7531\u4e8e Add \u51fd\u6570\u53ea\u80fd\u8ffd\u52a0\u5230\u5c3e\u90e8\u800c\u65e0\u6cd5\u5b8c\u6210\u3002\u65b0\u589e\u7684 Insert \u51fd\u6570\u53ef\u4ee5\u8f85\u52a9\u7528\u6237\u65b9\u4fbf\u7684\u5b8c\u6210\u6b64\u4f5c\u4e1a\u3002<\/p>\n<p>\u9996\u5148\u6211\u4eec\u770b\u51fd\u6570\u8bf4\u660e\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">    \/\/\/ &lt;summary&gt;\u63d2\u5165\u4e00\u4e2a\u4f5c\u4e1a\u8fc7\u7a0b\uff0c\u5982\u679c\u51c6\u5907\u5185\u90e8\u8ba1\u6570\u5668\u4e3a0\uff0c\u5219\u76f4\u63a5\u6267\u884c\uff0c\u5426\u5219\u53ea\u6dfb\u52a0\u5230\u5217\u8868&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"AIndex\"&gt;\u8981\u63d2\u5165\u7684\u7684\u4f4d\u7f6e\u7d22\u5f15&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AProc\"&gt;\u8981\u6267\u884c\u7684\u4f5c\u4e1a\u8fc7\u7a0b&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AData\"&gt;\u9644\u52a0\u6570\u636e\u6307\u9488&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AInMainThread\"&gt;\u4f5c\u4e1a\u662f\u5426\u9700\u8981\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AFreeType\"&gt;AData\u6307\u5b9a\u7684\u9644\u52a0\u6570\u636e\u6307\u9488\u91ca\u653e\u65b9\u5f0f&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u6210\u529f\uff0c\u8fd4\u56deTrue\uff0c\u5931\u8d25\uff0c\u8fd4\u56deFalse&lt;\/returns&gt;\r\n    \/\/\/ &lt;remarks&gt;\u6dfb\u52a0\u5230\u5206\u7ec4\u4e2d\u7684\u4f5c\u4e1a\uff0c\u8981\u4e48\u6267\u884c\u5b8c\u6210\uff0c\u8981\u4e48\u88ab\u53d6\u6d88\uff0c\u4e0d\u8fd0\u884c\u901a\u8fc7\u53e5\u67c4\u53d6\u6d88&lt;\/remarks&gt;\r\n    function Insert(AIndex:Integer;AProc: TQJobProc; AData: Pointer;\r\n      AInMainThread: Boolean = False;\r\n      AFreeType: TQJobDataFreeType = jdfFreeByUser): Boolean; overload;\r\n    \/\/\/ &lt;summary&gt;\u63d2\u5165\u4e00\u4e2a\u4f5c\u4e1a\u8fc7\u7a0b\uff0c\u5982\u679c\u51c6\u5907\u5185\u90e8\u8ba1\u6570\u5668\u4e3a0\uff0c\u5219\u76f4\u63a5\u6267\u884c\uff0c\u5426\u5219\u53ea\u6dfb\u52a0\u5230\u5217\u8868&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"AIndex\"&gt;\u8981\u63d2\u5165\u7684\u7684\u4f4d\u7f6e\u7d22\u5f15&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AProc\"&gt;\u8981\u6267\u884c\u7684\u4f5c\u4e1a\u8fc7\u7a0b&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AData\"&gt;\u9644\u52a0\u6570\u636e\u6307\u9488&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AInMainThread\"&gt;\u4f5c\u4e1a\u662f\u5426\u9700\u8981\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AFreeType\"&gt;AData\u6307\u5b9a\u7684\u9644\u52a0\u6570\u636e\u6307\u9488\u91ca\u653e\u65b9\u5f0f&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u6210\u529f\uff0c\u8fd4\u56deTrue\uff0c\u5931\u8d25\uff0c\u8fd4\u56deFalse&lt;\/returns&gt;\r\n    \/\/\/ &lt;remarks&gt;\u6dfb\u52a0\u5230\u5206\u7ec4\u4e2d\u7684\u4f5c\u4e1a\uff0c\u8981\u4e48\u6267\u884c\u5b8c\u6210\uff0c\u8981\u4e48\u88ab\u53d6\u6d88\uff0c\u4e0d\u8fd0\u884c\u901a\u8fc7\u53e5\u67c4\u53d6\u6d88&lt;\/remarks&gt;\r\n    function Insert(AIndex:Integer;AProc: TQJobProcG; AData: Pointer;\r\n      AInMainThread: Boolean = False;\r\n      AFreeType: TQJobDataFreeType = jdfFreeByUser): Boolean; overload;\r\n    {$IFDEF UNICODE}\r\n    \/\/\/ &lt;summary&gt;\u63d2\u5165\u4e00\u4e2a\u4f5c\u4e1a\u8fc7\u7a0b\uff0c\u5982\u679c\u51c6\u5907\u5185\u90e8\u8ba1\u6570\u5668\u4e3a0\uff0c\u5219\u76f4\u63a5\u6267\u884c\uff0c\u5426\u5219\u53ea\u6dfb\u52a0\u5230\u5217\u8868&lt;\/summary&gt;\r\n    \/\/\/ &lt;param name=\"AIndex\"&gt;\u8981\u63d2\u5165\u7684\u7684\u4f4d\u7f6e\u7d22\u5f15&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AProc\"&gt;\u8981\u6267\u884c\u7684\u4f5c\u4e1a\u8fc7\u7a0b&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AData\"&gt;\u9644\u52a0\u6570\u636e\u6307\u9488&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AInMainThread\"&gt;\u4f5c\u4e1a\u662f\u5426\u9700\u8981\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c&lt;\/param&gt;\r\n    \/\/\/ &lt;param name=\"AFreeType\"&gt;AData\u6307\u5b9a\u7684\u9644\u52a0\u6570\u636e\u6307\u9488\u91ca\u653e\u65b9\u5f0f&lt;\/param&gt;\r\n    \/\/\/ &lt;returns&gt;\u6210\u529f\uff0c\u8fd4\u56deTrue\uff0c\u5931\u8d25\uff0c\u8fd4\u56deFalse&lt;\/returns&gt;\r\n    \/\/\/ &lt;remarks&gt;\u6dfb\u52a0\u5230\u5206\u7ec4\u4e2d\u7684\u4f5c\u4e1a\uff0c\u8981\u4e48\u6267\u884c\u5b8c\u6210\uff0c\u8981\u4e48\u88ab\u53d6\u6d88\uff0c\u4e0d\u8fd0\u884c\u901a\u8fc7\u53e5\u67c4\u53d6\u6d88&lt;\/remarks&gt;\r\n    function Insert(AIndex:Integer;AProc: TQJobProcA; AData: Pointer;\r\n      AInMainThread: Boolean = False;\r\n      AFreeType: TQJobDataFreeType = jdfFreeByUser): Boolean; overload;\r\n    {$ENDIF}\r\n<\/pre>\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u4ee3\u7801\u53ef\u80fd\u5e2e\u52a9\u60a8\u7406\u89e3\u5176\u7528\u6cd5\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">unit Unit1;\r\n\r\ninterface\r\n\r\nuses\r\n  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,\r\n  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,QWorker;\r\n\r\ntype\r\n  TForm1 = class(TForm)\r\n    Button1: TButton;\r\n    procedure Button1Click(Sender: TObject);\r\n  private\r\n    { Private declarations }\r\n    procedure DoStep1(AJob:PQJob);\r\n    procedure DoStep2(AJob:PQJob);\r\n  public\r\n    { Public declarations }\r\n  end;\r\n\r\nvar\r\n  Form1: TForm1;\r\n\r\nimplementation\r\n\r\n{$R *.dfm}\r\n\r\nprocedure TForm1.Button1Click(Sender: TObject);\r\nvar\r\n  AGroup:TQJobGroup;\r\nbegin\r\nAGroup:=TQJobGroup.Create(True);\r\nAGroup.Prepare;\r\nAGroup.Add(DoStep1,nil);\r\nAGroup.Add(DoStep2,nil);\r\nAGroup.Run();\r\nAGroup.MsgWaitFor();\r\nAGroup.Free;\r\nend;\r\n\r\nprocedure TForm1.DoStep1(AJob: PQJob);\r\nbegin\r\nif IntPtr(AJob.Data)&lt;10 then\r\n  TQJobGroup(AJob.Group).Insert(0,DoStep1,Pointer(IntPtr(AJob.Data)+1));\r\nOutputDebugString(PChar('First:== '+IntToStr(IntPtr(AJob.Data))+' times Runed'));\r\nend;\r\n\r\nprocedure TForm1.DoStep2(AJob: PQJob);\r\nbegin\r\nOutputDebugString(PChar('Second:== '+IntToStr(IntPtr(AJob.Data))+' times Runed'));\r\nend;\r\n\r\nend.\r\n<\/pre>\n<p>\u6211\u4eec\u5728 DoStep1 \u4f5c\u4e1a\u4e2d\uff0c\u5982\u679c\u68c0\u67e5\u5230 AJob.Data \u7684\u503c&lt;10\uff0c\u5219\u63d2\u5165\u4e00\u4e2a\u81ea\u5df1\u7684\u4e00\u4e2a\u65b0\u4f5c\u4e1a\u505a\u4e3a\u4e0b\u4e00\u4e2a\u8981\u6267\u884c\u7684\u4f5c\u4e1a\uff0c\u8fd9\u6837\u5c31\u5f62\u6210\u4e0b\u9762\u7684\u8f93\u5165\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">First:==0 times Runed\r\nFirst:==1 times Runed\r\nFirst:==2 times Runed\r\nFirst:==3 times Runed\r\nFirst:==4 times Runed\r\nFirst:==5 times Runed\r\nFirst:==6 times Runed\r\nFirst:==7 times Runed\r\nFirst:==8 times Runed\r\nFirst:==9 times Runed\r\nFirst:==10 times Runed\r\nSecond:==0 times Runed<\/pre>\n<p>\u5982\u679c\u4e0d\u4f7f\u7528 Insert\uff0c\u800c\u4f7f\u7528Add\uff0c\u5219\u4f1a\u5f62\u6210\u4e0b\u9762\u7684\u8f93\u51fa\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">First:==0 times Runed\r\nSecond:==0 times Runed\r\nFirst:==1 times Runed\r\nFirst:==2 times Runed\r\nFirst:==3 times Runed\r\nFirst:==4 times Runed\r\nFirst:==5 times Runed\r\nFirst:==6 times Runed\r\nFirst:==7 times Runed\r\nFirst:==8 times Runed\r\nFirst:==9 times Runed\r\nFirst:==10 times Runed<\/pre>\n<p>\u3010\u66f4\u65b0\u7ea7\u522b\u3011<\/p>\n<p>\u53ef\u9009<\/p>\n<p>\u3010\u7279\u522b\u611f\u8c22\u3011<\/p>\n<p>\u8292\u679c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u66f4\u65b0\u8bf4\u660e\u3011 \u5982\u679c\u6211\u4eec\u5728\u987a\u5e8f\u4f5c\u4e1a\u6267\u884c\u8fc7\u7a0b [&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,6,2],"tags":[],"class_list":["post-2051","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-qworker","category-update"],"views":2885,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2051","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=2051"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2051\/revisions"}],"predecessor-version":[{"id":2052,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2051\/revisions\/2052"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}