06.11.2010, 09:12
|
|
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyThread = class(TThread)
private
dummy: Integer;
procedure Updt;
protected
procedure Execute; override;
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyThread: TMyThread;
implementation
{$R *.dfm}
{ TMyThread }
procedure TMyThread.Execute;
begin
dummy:=0;
while not Terminated do
begin
Synchronize(Updt);
Sleep(100);
Inc(dummy);
end;
dummy:=MaxInt;
Synchronize(Updt);
end;
{ TForm1 }
procedure TMyThread.Updt;
begin
Form1.Label1.Caption:=IntToStr(dummy);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if MyThread=nil then
begin
MyThread:=TMyThread.Create(True);
MyThread.FreeOnTerminate:=False;
MyThread.Resume;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if MyThread<>nil then
begin
MyThread.Terminate;
MyThread.WaitFor;
FreeAndNil(MyThread);
end;
end;
end.
http://data.cod.ru/73913
__________________
Пишу программы за еду.
__________________
|