请问在Delphi中我如果主线程中有个方法要同步访问(每次只允许一个线程访问)。有没有类似于java或者C中的Synchronize关键字作用的东西,让凡是访问这个方法的线程都是自动同步访问。用delphi的Synchronize好像必须在thread类中定义个方法,用这个方法去调用主程序的需要同步的方法,再用Synchronize(线程中的方法)方式调用。这样非常麻烦,尤其是线程中的方法好像还没法代参数。不知道有没有好的方法解决,谢谢!
调试欢乐多
Synchronize同步的
就是这样,不能带参数,需要另外写个不带参数的过程,调用你要的方法
begin
{ Place thread code here }
FreeOnTerminate := True;
Priority := tpLower ;// tpNormal;
while not (Terminated or Application.Terminated) do
begin
if HintForm=nil then
Terminate;
Sleep(100);//Below's is what you need
Synchronize(Application.ProcessMessages);
//Synchronize(Application.HandleMessage);
Synchronize(MyPro);
end;
end;