Показать сообщение отдельно
  #8  
Старый 17.05.2015, 07:18
nikola129 nikola129 вне форума
Прохожий
 
Регистрация: 16.05.2015
Сообщения: 4
Версия Delphi: Delphi2006
Репутация: 10
По умолчанию

С потоками я дела не имел, но интернет по подобным ссылкам просмотрел.
Пробовал это:
Код:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TNewThread = class(TThread)
  private
  protected
      procedure Execute; override;
  public
    { Public declarations }
  end;
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const n=3;
var
  Form1: TForm1;
  thread: array[0..n] of TNewThread;
implementation

{$R *.dfm}
procedure TNewThread.Execute;
  var i: byte;
begin
  for I := 0 to n do
    while true do {ничего не делаем}
      if thread[i].Terminated  then
        break;

end;

procedure TForm1.Button1Click(Sender: TObject);
 var i: Integer;
begin
  for i := 0 to n do
  begin
    thread[i]:= TNewThread.Create(true);
    thread[i].FreeOnTerminate:= true;
    thread[i].Priority:= tpLower;
    thread[i].Resume;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
  var i: Integer;
begin
 for i := 0 to n do
   if not thread[i].Terminated   then
     thread[i].Terminate;
   ShowMessage('Завершение работы потоков');
end;

end.
Грузит все четыре ядра. Нашел интересное: http://www.delphikingdom.ru/asp/view...catalogid=1355
но это не работает, как хотелось.
Ответить с цитированием