Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Реферат - Потоки / lab4thread2 / synchron / thrdu
.pas unit thrdu;
interface
uses
Classes;
type
testthrd = class(TThread)
private
{ Private declarations }
ans:integer;
s:string;
protected
procedure giveans;
procedure gives;
procedure Execute; override;
end;
implementation
{ 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 testthrd.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
uses sysutils,main;
{ testthrd }
procedure testthrd.giveans;
begin
mainform.Edit1.Text:=inttostr(ans);
end;
procedure testthrd.gives;
begin
mainform.Edit2.Text:=s;
end;
procedure testthrd.Execute;
var i:integer;
begin
{ Place thread code here }
s:='Hello from threadland';
freeonterminate:=true;
for i:=1 to 10000 do
begin
if terminated then break;
inc(ans,round(abs(sin(sqrt(i)))));
synchronize(giveans);
synchronize(gives);
end;
end;
end.
interface
uses
Classes;
type
testthrd = class(TThread)
private
{ Private declarations }
ans:integer;
s:string;
protected
procedure giveans;
procedure gives;
procedure Execute; override;
end;
implementation
{ 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 testthrd.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
uses sysutils,main;
{ testthrd }
procedure testthrd.giveans;
begin
mainform.Edit1.Text:=inttostr(ans);
end;
procedure testthrd.gives;
begin
mainform.Edit2.Text:=s;
end;
procedure testthrd.Execute;
var i:integer;
begin
{ Place thread code here }
s:='Hello from threadland';
freeonterminate:=true;
for i:=1 to 10000 do
begin
if terminated then break;
inc(ans,round(abs(sin(sqrt(i)))));
synchronize(giveans);
synchronize(gives);
end;
end;
end.