delphi 线程

function ThreadFunc(P:Pointer):LongInt;stdcall;
var
i:Integer;
dc:HDC;
s:string;
begin
dc := GetDC(Form2.Handle);
for i := 0 to 10000 do
begin
s := IntToStr(i);
TextOut(dc,10,10,PChar(s),Length(s));
end;
ReleaseDC(Form2.Handle,dc);
end;



procedure TForm2.btn1Click(Sender: TObject);
var
hthread:THandle;
ThreadId:DWORD;
begin
hthread := CreateThread(nil,
0,
@ThreadFunc,//函数地址
nil,
0,
ThreadId
);
if ThreadId = 0 then
MessageBox(Handle,'NO thread',nil,MB_OK);
end;

procedure TForm2.btn2Click(Sender: TObject);
begin
ThreadFunc(nil);
end;

你可能感兴趣的:(thread,线程,Delphi)