unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type // Объявление класса потока-потомка
TSimpleThread = class(TThread)
Edit: TEdit;
procedure Execute; override;
procedure oper;
public
procedure OutMessage;
end;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
procedure TrackBar1Change(Sender: TObject);
procedure TrackBar2Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Thread1: TSimpleThread; // Экземпляр класса «поток»
Thread2: TSimpleThread; // Экземпляр класса «поток»
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure TSimpleThread.Execute;
begin
// Содержание потока
while not Terminated do
begin
Synchronize(OutMessage);
Synchronize(oper);
sleep(1);
end;
end;
procedure tsimplethread.oper;
begin
Edit.Tag:=Edit.Tag+1;
end;
procedure TSimpleThread.OutMessage;
begin
Edit.Text:=IntToStr(Edit.Tag); // Обращение к VCL
end;
{$R *.dfm}
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Thread1.Suspend;
if Trackbar1.position=0 then thread1.Priority:=tpidle;
if Trackbar1.position=1 then thread1.Priority:=tplowest;
if Trackbar1.position=2 then thread1.Priority:=tplower;
if Trackbar1.position=3 then thread1.Priority:=tpNormal;
if Trackbar1.position=4 then thread1.Priority:=tphigher;
if Trackbar1.position=5 then thread1.Priority:=tphighest;
if Trackbar1.position=6 then thread1.Priority:=tpTimeCritical;
Thread1.Resume;
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
begin
Thread2.Suspend;
if Trackbar2.position=0 then thread2.Priority:=tpidle;
if Trackbar2.position=1 then thread2.Priority:=tplowest;
if Trackbar2.position=2 then thread2.Priority:=tplower;
if Trackbar2.position=3 then thread2.Priority:=tpNormal;
if Trackbar2.position=4 then thread2.Priority:=tphigher;
if Trackbar2.position=5 then thread2.Priority:=tphighest;
if Trackbar2.position=6 then thread2.Priority:=tpTimeCritical;
Thread2.Resume;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Thread1:= TSimpleThread.Create(true); // Экземпляр класса «поток»
Thread1.Edit := Edit1;
Thread1.Resume;
Thread2:= TSimpleThread.Create(true); // Экземпляр класса «поток»
Thread2.Edit := Edit2;
Thread2.Resume;
end;
end.
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.