Показать сообщение отдельно
  #2  
Старый 13.01.2013, 23:29
AlexSku AlexSku вне форума
Специалист
 
Регистрация: 07.05.2007
Адрес: Москва
Сообщения: 884
Репутация: 21699
По умолчанию

Можно сделать так:
Код:
type
  ThMy = class(TThread)
  private
    Msg: string;
    procedure ShowMsg;
  protected
    procedure Execute; override;
  end;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    th: array[0..2] of ThMy;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ThMy.Execute;
  var
  i: Integer;
begin
  while not Terminated do begin
    Inc(i);
    Sleep(10);
  end;
  Synchronize(ShowMsg);
end;

procedure ThMy.ShowMsg;
begin
  ShowMessage('конец');
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to 2 do begin
    th[i]:= ThMy.Create(true);
    th[i].FreeOnTerminate:= false;
    th[i].Priority:= tpNormal;
    th[i].Resume;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if not Assigned(th[0]) then
    ShowMessage('нет потока 0')
  else
  begin
    th[0].Terminate;
    th[0]:= nil;
  end;
end;
Ответить с цитированием