据说Event(事件对象)是多线程最原始的同步手段,我觉得它是最灵活的一个.Event对象(的句柄表)中主要有两个布尔变量,从它的建立函数中可以看得清楚:functionCreateEvent(lpEventAttributes:PSecurityAttributes;{安全设置}bManualReset:BOOL;{第一个布尔}bInitialState:BOOL;{第二个布尔}lpName:PWideChar{对象名称}):THandle;stdcall;{返回对象句柄}//第一个布尔为False时,事件对象控制一次后将立即重置(暂停);为True时可手动暂停.//第二个布尔为False时,对象建立后控制为暂停状态;True是可运行状态.和其他同类相比,它的灵活性在于可随时"启动运行"(SetEvent)和"暂停运行"(ResetEvent);甚至还有个PulseEvent函数,能控制执行一次后立即暂停,很是方便.本例效果图:代码文件:unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Button1:TButton;Button2:TButton;Button3:TButton;Button4:TButton;Button5:TButton;procedureFormCreate(Sender:TObject);procedureFormDestroy(Sender:TObject);procedureButton1Click(Sender:TObject);procedureButton2Click(Sender:TObject);procedureButton3Click(Sender:TObject);procedureButton4Click(Sender:TObject);procedureButton5Click(Sender:TObject);end;varForm1:TForm1;implementation{$R*.dfm}varf:Integer;{用这个变量协调一下各线程输出的位置}hEvent:THandle;{事件对象的句柄}functionMyThreadFun(p:Pointer):DWORD;stdcall;vari,y:Integer;beginInc(f);y:=20*f;fori:=0to200000dobeginifWaitForSingleObject(hEvent,INFINITE)=WAIT_OBJECT_0thenbeginForm1.Canvas.Lock;Form1.Canvas.TextOut(20,y,IntToStr(i));Form1.Canvas.Unlock;end;end;Result:=0;end;procedureTForm1.Button1Click(Sender:TObject);beginRepaint;f:=0;CloseHandle(hEvent);{如果已经创建过}hEvent:=CreateEvent(nil,True,True,nil);end;{创建线程}procedureTForm1.Button2Click(Sender:TObject);varThreadID:DWORD;beginCreateThread(nil,0,@MyThreadFun,nil,0,ThreadID);end;{暂停}procedureTForm1.Button3Click(Sender:TObject);beginResetEvent(hEvent);end;{启动}procedureTForm1.Button4Click(Sender:TObject);beginSetEvent(hEvent);end;{启动后执行一次立即暂停}procedureTForm1.Button5Click(Sender:TObject);beginPulseEvent(hEvent);end;procedureTForm1.FormCreate(Sender:TObject);beginButton1.Caption:='创建Event对象';Button2.Caption:='创建线程';Button3.Caption:='ResetEvent';Button4.Caption:='SetEvent';Button5.Caption:='PulseEvent';end;procedureTForm1.FormDestroy(Sender:TObject);beginCloseHandle(hEvent);end;end.窗体文件:objectForm1:TForm1Left=0Top=0Caption='Form1'ClientHeight=149ClientWidth=228Color=clBtnFaceFont.Charset=DEFAULT_CHARSETFont.Color=clWindowTextFont.Height=-11Font.Name='Tahoma'Font.Style=[]OldCreateOrder=FalseOnCreate=FormCreatePixelsPerInch=96TextHeight=13objectButton1:TButtonLeft=8Top=116Width=129Height=25Caption='Button1'TabOrder=0OnClick=Button1ClickendobjectButton3:TButtonLeft=143Top=12Width=75Height=25Caption='Button3'TabOrder=1OnClick=Button3ClickendobjectButton4:TButtonLeft=143Top=43Width=75Height=25Caption='Button4'TabOrder=2OnClick=Button4ClickendobjectButton5:TButtonLeft=143Top=74Width=75Height=25Caption='Button5'TabOrder=3OnClick=Button5ClickendobjectButton2:TButtonLeft=143Top=116Width=75Height=25Caption='Button2'TabOrder=4OnClick=Button2Clickendend和前面一样,再用SyncObjs单元下的TEvent类实现一次;不过它没有实现类似PulseEvent的功能:unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Button1:TButton;Button2:TButton;Button3:TButton;Button4:...