|
From: Peter T. <pe...@us...> - 2003-08-23 23:20:33
|
Update of /cvsroot/jvcl/dev/JVCL3/examples/JvThread
In directory sc8-pr-cvs1:/tmp/cvs-serv5637/JVCL3/examples/JvThread
Added Files:
JvThreadProj.dof JvThreadProj.dpr JvThreadProj.res fThread.dfm
fThread.pas
Log Message:
- Copied jvcl/devtools and jvcl/examples dev/JVCL3
- Copied JVCLConvert *.dat files to dev/JVCL3/converter
--- NEW FILE: JvThreadProj.dof ---
[Directories]
OutputDir=..\..\Bin
UnitOutputDir=..\..\Dcu
SearchPath=..\..\Source;..\..\Common
--- NEW FILE: JvThreadProj.dpr ---
program JvThreadProj;
uses
Forms,
fThread in 'fThread.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
--- NEW FILE: JvThreadProj.res ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: fThread.dfm ---
object Form1: TForm1
Left = 353
Top = 149
Width = 422
Height = 133
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 244
Top = 32
Width = 50
Height = 13
Caption = 'Job1 Stats'
end
object Label2: TLabel
Left = 312
Top = 32
Width = 3
Height = 13
end
object Label3: TLabel
Left = 244
Top = 58
Width = 50
Height = 13
Caption = 'Job2 Stats'
end
object Label4: TLabel
Left = 312
Top = 58
Width = 3
Height = 13
end
object Button1: TButton
Left = 52
Top = 18
Width = 75
Height = 25
Caption = 'Start Job 1'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 52
Top = 54
Width = 75
Height = 25
Caption = 'Start Job 2'
TabOrder = 1
OnClick = Button2Click
end
object JvThread1: TJvThread
Exclusive = True
RunOnCreate = True
FreeOnTerminate = True
OnExecute = JvThread1Execute
Left = 6
Top = 6
end
object JvThread2: TJvThread
Exclusive = True
RunOnCreate = True
FreeOnTerminate = True
OnExecute = JvThread2Execute
Left = 6
Top = 44
end
end
--- NEW FILE: fThread.pas ---
unit fThread;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, JvThread, JvComponent;
type
TForm1 = class(TForm)
Label1: TLabel;
JvThread1: TJvThread;
JvThread2: TJvThread;
Button1: TButton;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button2: TButton;
procedure JvThread1Execute(Sender: TObject; params: Pointer);
procedure Button1Click(Sender: TObject);
procedure JvThread2Execute(Sender: TObject; params: Pointer);
procedure Button2Click(Sender: TObject);
private
public
Value: Integer;
Value2: Integer;
procedure Stats1(Sender: TObject);
procedure Stats2(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.JvThread1Execute(Sender: TObject; params: Pointer);
var
i,j,k: Integer;
begin
//Do the job here
k := 0;
for i:=0 to 1000000 do
for j:=0 to 1000000 do
begin
inc(k);
//To use global variable/objects, you have to synchronize (to avoid conflicts)
TForm1(params).Value := k;
Synchronize(TForm1(params).Stats1);
end;
end;
procedure TForm1.JvThread2Execute(Sender: TObject; params: Pointer);
var
i,j,k: Integer;
begin
//Do the job here
k := 0;
for i:=0 to 1000000 do
for j:=0 to 1000000 do
begin
inc(k,5); //This is the only difference with the other thread
//To use global variable/objects, you have to synchronize (to avoid conflicts)
TForm1(params).Value2 := k;
Synchronize(TForm1(params).Stats2);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
JvThread1.Execute(self);
(Sender as TButton).Enabled := false;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
JvThread2.Execute(self);
(Sender as TButton).Enabled := false;
end;
procedure TForm1.Stats1(Sender: TObject);
begin
Label2.Caption := IntToStr(Value);
end;
procedure TForm1.Stats2(Sender: TObject);
begin
Label4.Caption := IntToStr(Value2);
end;
end.
|