function ThreadFunc(P: Pointer): LongInt; stdcall; var i: Integer; DC: HDC; S: string; begin DC := GetDC(Form1.Handle); SetBkColor(DC, GetSysColor(color_btnface)); for i := 0 to 100000 do begin S := IntToStr(i); TextOut(DC, 10, 10, PChar(S), Length(S)); end; ReleaseDC(Form1.Handle, DC); end;
//采用一个多线程 procedure TForm1.Button4Click(Sender: TObject); var hThread: THandle; ThreadID: DWord; begin hthread := CreateThread(nil, //Security attribute 0, //Initial Stack @ThreadFunc, //Starting address of thread nil, // argument of thread 0, // Create flags ThreadID); // thread ID
if hthread = 0 then MessageBox(Handle, 'No Thread', nil, MB_OK); end;
//采用单线程 procedure TForm1.Button5Click(Sender: TObject); begin ThreadFunc(nil); end;