![]() |
Главная Случайная страница Контакты | Мы поможем в написании вашей работы! | |
|
Маin программасы:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, mythread;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
co:TCountObj;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
co:=TCountObj.create(true);
co.resume;
co.priority:=tpLower;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
co.terminate;
end;
end.
My Thread ағынның программасы:
unit myThread;
interface
uses
Classes,sysutils;
type
TCountObj = class(TThread)
private
{ Private declarations }
index:integer;
procedure Updatelabel;
protected
procedure Execute; override;
end;
implementation
uses main;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TCountObj.UpdateCaption;
begin
Form1.Caption:= 'Updated in a thread';
end; }
{ TCountObj }
procedure TCountObj.Updatelabel;
begin
Form1.label1.Caption:= IntToStr(index);
end;
procedure TCountObj.Execute;
begin
{ Place thread code here }
index:=1;
while index>0 do
begin
Synchronize(UpdateLabel);
inc(index);
if index>100000 then
index:=0;
if terminated then exit
end;
end;
end.
Дата публикования: 2015-10-09; Прочитано: 216 | Нарушение авторского права страницы | Мы поможем в написании вашей работы!