https://www.cnblogs.com/chaosc/p/5819178.html
------------------------一部分内容
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override; {执行}
procedure Run; {声明多一个过程,把功能代码写在这里再给Execute调用}
end;
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
MyThread:TMyThread; {声明一个线程类对象}
procedure TMyThread.Run;
var
i:integer;
begin
for i := 0 to 500000 do
begin
Form1.Canvas.Lock;
Form1.Canvas.TextOut(10,10,IntToStr(i));
Form1.Canvas.Unlock; //注意调用的空间都得标注其来源 ,比如form1.
end;
end;
procedure TMyThread.Execute;
begin
{ Place thread code here }
FreeOnTerminate:=True; {加上这句线程用完了会自动注释}
Run;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
MyThread:=TMyThread.Create(False); {实例化这个类,为False时立即运行,为True时可加MyThread.Resume用来启动}
end;
----------------------------------------