标签:procedure 一个 cti .class create color creat bool dia
unit Unit15; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Threading, kbmmwprocess, Vcl.StdCtrls, kbmMWClientDataset; type TForm15 = class(TForm) Button1: TButton; kbmMWClientTransactionResolver1: TkbmMWClientTransactionResolver; Button2: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); private FTaskIsRunning: boolean; cnt: Integer; { Private declarations } public { Public declarations } end; var Form15: TForm15; implementation {$R *.dfm} procedure TForm15.Button1Click(Sender: TObject); begin FTaskIsRunning := true; TTask.Run( procedure begin while FTaskIsRunning do begin sleep(99); TThread.Synchronize(nil, procedure begin Label1.Caption := ‘Thread is running...‘ + cnt.ToString; inc(cnt); end); end; end); end; procedure TForm15.Button2Click(Sender: TObject); begin FTaskIsRunning := false; cnt := 0; end; procedure TForm15.FormCreate(Sender: TObject); begin FTaskIsRunning := false; cnt := 0; end; end.
上面的代码,运行正常,按Button1开启一个线程,Button2终止线程运行。这是一个VCL项目。
标签:procedure 一个 cti .class create color creat bool dia
原文地址:https://www.cnblogs.com/kinglandsoft/p/10367549.html