Advertisement
JUST_BENCH

+Thread

Aug 7th, 2017
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.80 KB | None | 0 0
  1. Function StartThread(pFunction: TFNThreadStartRoutine;
  2.   iPriority: Integer = Thread_Priority_Normal; iStartFlag: Integer = 0)
  3.   : THandle;
  4. var
  5.   ThreadID: DWORD;
  6. begin
  7.   Result := CreateThread(nil, 0, pFunction, nil, iStartFlag, ThreadID);
  8.   if Result <> Null then
  9.     SetThreadPriority(Result, iPriority);
  10. end;
  11.  
  12. Function CloseThread(ThreadHandle: THandle): Boolean;
  13. begin
  14.   Result := TerminateThread(ThreadHandle, 1);
  15.   CloseHandle(ThreadHandle);
  16. end;
  17.  
  18. procedure Test;
  19. begin
  20.   Delay(1000);
  21.   FormMain.Edit1.Text := FormMain.Edit1.Text + 'ok ';
  22.   //ShowMessage('kk');
  23. end;
  24.  
  25. procedure TFormMain.Button14Click(Sender: TObject);
  26. var
  27.   h: Cardinal;
  28.   hThread: THandle;
  29. begin
  30.   hThread := StartThread(@Test);
  31.   FormMain.Edit2.Text := FormMain.Edit2.Text + 'ok ';
  32.   CloseThread(hThread);
  33. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement