现在的位置: 首页 > 综合 > 正文

delphi中临界操作方法

2013年12月02日 ⁄ 综合 ⁄ 共 832字 ⁄ 字号 评论关闭

 

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;

 

抱歉!评论已关闭.