Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Реферат - Потоки / prior4 / mythrd
.pas unit mythrd;
interface
uses
Classes,Graphics,Windows,SysUtils,StdCtrls,syncobjs;
type
tmythread = class(TThread)
private
{ Private declarations }
counter:tedit;
count:integer;
protected
procedure Execute; override;
public
constructor Create(lb:tedit);
end;
implementation
uses unit1;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure tmythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ tmythread }
constructor tmythread.Create(lb:tedit);
begin
counter:=lb;
count:=1;
inherited create(true);
end;
procedure tmythread.Execute;
begin
{ Place thread code here }
repeat
count:=count+1;
with Critical do begin
enter;
counter.Text:=inttostr(count);
leave;
end;
until count=1000;
end;
end.
interface
uses
Classes,Graphics,Windows,SysUtils,StdCtrls,syncobjs;
type
tmythread = class(TThread)
private
{ Private declarations }
counter:tedit;
count:integer;
protected
procedure Execute; override;
public
constructor Create(lb:tedit);
end;
implementation
uses unit1;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure tmythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ tmythread }
constructor tmythread.Create(lb:tedit);
begin
counter:=lb;
count:=1;
inherited create(true);
end;
procedure tmythread.Execute;
begin
{ Place thread code here }
repeat
count:=count+1;
with Critical do begin
enter;
counter.Text:=inttostr(count);
leave;
end;
until count=1000;
end;
end.