//主程序Unit1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyIndex: Integer;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
var
ThreadTmp: MyThread;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyIndex := 0;
ThreadTmp := MyThread.Create(false);
end;
end.
//线程Unit2
unit Unit2;
interface
uses
Classes, SysUtils;
type
MyThread = class(TThread)
private
{ Private declarations }
Procedure MyPro;
protected
procedure Execute;
override;
end;
implementation
uses Unit1;
procedure MyThread.Execute;
begin
{ Place thread code here }
while not Terminateddo
Synchronize(MyPro);
//循环执行自己定义的过程
end;
procedure MyThread.MyPro;
begin
Inc(Form1.MyIndex);
Form1.Edit1.Text := IntToStr(Form1.MyIndex);
Form1.Edit2.Text := IntToStr(Form1.MyIndex);
Sleep(20);
end;
end.
//这只不过是简单的代码,你可以去查查资料,DFW以前的贴子说得也多!
//拖动窗体是,没有任何停顿的感觉
//如果用Timer定义时,就会出现停顿