unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, syncobjs;<br><br>type<br> TForm1 = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> private<br> cs: TCriticalSection;<br> procedure mtAccess;<br> public<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> cs := TCriticalSection.Create;<br>end;<br><br>procedure TForm1.mtAccess;<br>begin<br> cs.Enter;<br> try<br> //临界数据访问<br> //...<br> finally<br> cs.Leave;<br> end;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> cs.Free;<br>end;<br><br>end.<br>