Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @foo
- interface
- type
- TProcRef = reference to procedure;
- TWorkerThread = class(TThread)
- public
- proc: TProcRef;
- procedure Execute; override;
- class procedure RunInThread(AProc: TProcRef);
- end;
- implementation
- procedure TWorkerThread.Execute;
- begin
- inherited;
- proc;
- end;
- class procedure TWorkerThread.RunInThread(AProc: TProcRef);
- begin
- with TWorkerThread.Create(true) do
- begin
- FreeOnTerminate := true;
- proc := AProc;
- Resume;
- end;
- end;
- procedure P;
- begin
- while true do
- begin
- sleep(1000);
- beep;
- end;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- TWorkerThread.RunInThread(P);
- end;
- TWorkerThread.RunInThread(procedure begin while true do begin sleep(1000); beep; end; end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement