//定于互斥对象
var
EventHandle_in:Thandle;
//定于这几个过程
Procedure CreateEvent_Thread(EventName:string);
Procedure EnterCriticalSection_Thread;
Procedure LeaveCriticalSection_Thread;
//创建输入互斥对象
Procedure CreateEvent_Thread(EventName:string);
begin
EventHandle_in:=CreateEvent(nil,false,true,pchar(EventName));
end;
//进入输入互斥区
Procedure EnterCriticalSection_Thread;
begin
WaitForSingleObject(EventHandle_in,INFINITE);
end;
//离开输入互斥区
Procedure LeaveCriticalSection_Thread;
begin
setEvent(EventHandle_in);
end;
//然后在程序最前面调用这个生成互斥对象
CreateEvent_Thread('huajiyong');
//然后再用到全局变量的时候时候:
EnterCriticalSection_Thread;//进入互斥区
{处理全局变量}
LeaveCriticalSection_Thread;//退出互斥区