K
kenmen
Unregistered / Unconfirmed
GUEST, unregistred user!
有这个程序,是关于线程的:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Paintth;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
PT: TPainterThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
PT := TPainterThread.Create (False);
// start
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PT.Free;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Canvas.Pen.Color := Color;
// of the form
Canvas.Brush.Color := Color;
Canvas.Ellipse (x - 30, y - 30, x + 30, y + 30);
end;
end.
unit paintth;
interface
uses
Classes;
type
TPainterThread = class(TThread)
private
X, Y: Integer;
protected
procedure Execute;
override;
procedure Paint;
end;
implementation
{ TPainterThread }
uses
MainForm, Graphics;
procedure TPainterThread.Paint;
begin
Form1.Canvas.Pixels [X, Y] := clRed;
end;
procedure TPainterThread.Execute;
begin
Randomize;
repeat
X := Random (300);
Y := Random (Form1.ClientHeight);
Synchronize (Paint);
until Terminated;
end;
end.
我想问,unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Paintth;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
PT: TPainterThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
PT := TPainterThread.Create (False);
// start
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PT.Free;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Canvas.Pen.Color := Color;
// of the form
Canvas.Brush.Color := Color;
Canvas.Ellipse (x - 30, y - 30, x + 30, y + 30);
end;
end.
unit paintth;
interface
uses
Classes;
type
TPainterThread = class(TThread)
private
X, Y: Integer;
protected
procedure Execute;
override;
procedure Paint;
end;
implementation
{ TPainterThread }
uses
MainForm, Graphics;
procedure TPainterThread.Paint;
begin
Form1.Canvas.Pixels [X, Y] := clRed;
end;
procedure TPainterThread.Execute;
begin
Randomize;
repeat
X := Random (300);
Y := Random (Form1.ClientHeight);
Synchronize (Paint);
until Terminated;
end;
end.
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Paintth;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
PT: TPainterThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
PT := TPainterThread.Create (False);
// start
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PT.Free;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Canvas.Pen.Color := Color;
// of the form
Canvas.Brush.Color := Color;
Canvas.Ellipse (x - 30, y - 30, x + 30, y + 30);
end;
end.
unit paintth;
interface
uses
Classes;
type
TPainterThread = class(TThread)
private
X, Y: Integer;
protected
procedure Execute;
override;
procedure Paint;
end;
implementation
{ TPainterThread }
uses
MainForm, Graphics;
procedure TPainterThread.Paint;
begin
Form1.Canvas.Pixels [X, Y] := clRed;
end;
procedure TPainterThread.Execute;
begin
Randomize;
repeat
X := Random (300);
Y := Random (Form1.ClientHeight);
Synchronize (Paint);
until Terminated;
end;
end.
我想问:Synchronize 有啥用?我去掉它程序一样可运行。
还有,怎样知一个线程是主线程?
请高手们详细点,我对线程还是初鸟!!!!!
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Paintth;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
PT: TPainterThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
PT := TPainterThread.Create (False);
// start
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PT.Free;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Canvas.Pen.Color := Color;
// of the form
Canvas.Brush.Color := Color;
Canvas.Ellipse (x - 30, y - 30, x + 30, y + 30);
end;
end.
unit paintth;
interface
uses
Classes;
type
TPainterThread = class(TThread)
private
X, Y: Integer;
protected
procedure Execute;
override;
procedure Paint;
end;
implementation
{ TPainterThread }
uses
MainForm, Graphics;
procedure TPainterThread.Paint;
begin
Form1.Canvas.Pixels [X, Y] := clRed;
end;
procedure TPainterThread.Execute;
begin
Randomize;
repeat
X := Random (300);
Y := Random (Form1.ClientHeight);
Synchronize (Paint);
until Terminated;
end;
end.
我想问,unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Paintth;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
PT: TPainterThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
PT := TPainterThread.Create (False);
// start
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PT.Free;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Canvas.Pen.Color := Color;
// of the form
Canvas.Brush.Color := Color;
Canvas.Ellipse (x - 30, y - 30, x + 30, y + 30);
end;
end.
unit paintth;
interface
uses
Classes;
type
TPainterThread = class(TThread)
private
X, Y: Integer;
protected
procedure Execute;
override;
procedure Paint;
end;
implementation
{ TPainterThread }
uses
MainForm, Graphics;
procedure TPainterThread.Paint;
begin
Form1.Canvas.Pixels [X, Y] := clRed;
end;
procedure TPainterThread.Execute;
begin
Randomize;
repeat
X := Random (300);
Y := Random (Form1.ClientHeight);
Synchronize (Paint);
until Terminated;
end;
end.
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Paintth;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
PT: TPainterThread;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
PT := TPainterThread.Create (False);
// start
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PT.Free;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Canvas.Pen.Color := Color;
// of the form
Canvas.Brush.Color := Color;
Canvas.Ellipse (x - 30, y - 30, x + 30, y + 30);
end;
end.
unit paintth;
interface
uses
Classes;
type
TPainterThread = class(TThread)
private
X, Y: Integer;
protected
procedure Execute;
override;
procedure Paint;
end;
implementation
{ TPainterThread }
uses
MainForm, Graphics;
procedure TPainterThread.Paint;
begin
Form1.Canvas.Pixels [X, Y] := clRed;
end;
procedure TPainterThread.Execute;
begin
Randomize;
repeat
X := Random (300);
Y := Random (Form1.ClientHeight);
Synchronize (Paint);
until Terminated;
end;
end.
我想问:Synchronize 有啥用?我去掉它程序一样可运行。
还有,怎样知一个线程是主线程?
请高手们详细点,我对线程还是初鸟!!!!!