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;
本文详细介绍了临界区操作如何在类中实现,包括初始化、进入、退出和删除临界区域的方法,以及在类创建和销毁过程中的具体应用。
128

被折叠的 条评论
为什么被折叠?



