unit Thread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
m:integer;
implementation
{$R *.dfm}
var
ThreadIdHandle:THandle;
function ThreadProc(Info
ointer):integer;stdcall;
var
S:String;
begin
inc(m);
//Form1.Invalidate;
Form1.Canvas.TextOut(10,10,Inttostr(m));
Sleep(5000);
SuspendThread(ThreadIdHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ThreadId: DWORD;
ExitCode
WORD;
begin
ThreadIdHandle:=CreateThread(nil,0,@ThreadProc,nil,CREATE_SUSPENDED,ThreadId);
ResumeThread(ThreadIdHandle);
sleep(1000);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ResumeThread(ThreadIdHandle);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
m:=0;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SuspendThread(ThreadIdHandle);
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
ExitCode: DWORD; // holds the thread exit code
begin
{retrieve and display the thread's exit code}
GetExitCodeThread(ThreadIdHandle, ExitCode);
end;
end.
//按button3 后再按button4
//怎么m的值怎么没有改变