delphi中临界操作方法
2008-05-09 19:48
var
FLock:TRTLCriticalSection; //定义临界区域
begin
InitializeCriticalSection(FLock); //初始化临界区域
EnterCriticalSection(FLock); //进入临界区域
LeaveCriticalSection(FLock); //退出临界区域
DeleteCriticalSection(FLock);//删除临界区域
end;
//CLASS中使用实例
TRegGroups = class
private
.............
FLock: TRTLCriticalSection;
................
public
...........
constructor Create;
destructor Destroy; override;
procedure Lock;
procedure Unlock;
................
end;
var
RegGroups: TRegGroups;
constructor TRegGroups.Create;
begin
inherited Create;
................
InitializeCriticalSection(FLock);
.....................
end;
destructor TRegGroups.Destroy;
begin
DeleteCriticalSection(FLock);
.......................
inherited;
end;
procedure TRegGroups.Lock;
begin
EnterCriticalSection(FLock);
end;
procedure TRegGroups.Unlock;
begin
LeaveCriticalSection(FLock);
|