delphi中临界操作方法

 

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);
end;

 

你可能感兴趣的:(Delphi)