请帮忙举个实例.非常简单(20分)

  • 主题发起人 主题发起人 我饿了
  • 开始时间 开始时间

我饿了

Unregistered / Unconfirmed
GUEST, unregistred user!
请给我举个多线程的实例.~~~
简单的就行.
请学出源码.
谢谢!!!!!!!!
 
Delphi不是自带一个 多线程排序的例子?
 
运行本程序前先在FORM上放两个SHAPE。
unit usndth;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons;
type
TBallThread = class(TThread)
private
shap : Tshape;
x,y : integer;
maxx,maxy : integer;
procedure moveball;
// property
protected
procedure execute;override;
public
constructor create(s:tshape;w,h,i,j:integer);
end;

TfMain = class(TForm)
Shape1: TShape;
Shape2: TShape;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
fMain: TfMain;
b1,b2 : TballThread;
implementation
{$R *.DFM}
constructor TballThread.create(s:tshape;w,h,i,j:integer);
begin
Inherited create(false);
shap := s;
x := i;
y := j;
maxx :=w;
maxy :=h;
FreeOnterminate := True;
end;
procedure TballThread.moveball;
begin
with shapdo
begin
if (left <=0) or (Width+left > maxx) then
x := x * -1;
if (top <=0) or (top + height > maxy) then
y := y * -1;
left := left + x;
top := top + y;
end;
end;
procedure TballThread.execute ;
begin
while not terminateddo
Synchronize(moveball);
end;
procedure TfMain.BitBtn1Click(Sender: TObject);
begin
b1 := TballThread.create(shape1,fmain.Width ,fmain.Height ,1,1);
end;

procedure TfMain.BitBtn2Click(Sender: TObject);
begin
b2 := TballThread.create(shape2,fmain.width,height,2,2);
end;

end.
 
两个SHAPE会分别按自己的路径算法行动。
 
program friles/borland/delphi5/demos/threads/
 
接受答案了.
 
后退
顶部