Delphi里面的TCriticalSection对象的用法(如何使用锁)
Delphi里面的TCriticalSection对象是将包含它的对象给锁住。
比如:
TAsioDataBuffer = class
procedure Setstate(const Value: Integer); //数据锁
public
FDataLock, FSendLock: TCriticalSection;
Writedata, SendData, Data1, data2: TMemoryStream;
end;
var
MyAsioDataBuffer: TAsioDataBuffer;
begin
//这一句是将MyAsioDataBuffer对象锁住,而不是将Writedata锁住,只不过因为MyAsioDataBuffer对象包含了Writedata对象,所以Writedata也被锁住了,就是MyAsioDataBuffer里的所有东西都被锁住了。
MyAsioDataBuffer.FSendLock.Acquire;
end;