Can  someone  tell  me  how  to  use  Synchronize  method  within  IdTCPServer.OnExecute  event.  I  want  to  access  some  component  on  a  main  form  and  I  read  that  you  cannot  
access  it  directly  from  OnExecute  event  safely.  But  when  I  call  Synchronize  method  where  I  access  main  form's  component  I  get  Access  violation  error.  

解决方案 »

  1.   

    paste the main code here!
      

  2.   

    Use the Thread approach
      

  3.   

    // Synchronize example
    // This example shows how to call a button抯 click method in a thread-safe manner:
    procedure TMyThread.PushTheButton;begin
      Button1.Click();
    end;procedure TMyThread.Execute;
    begin
    ...
      Synchronize(PushTheButton);
      ...
    end;
      

  4.   


    procedure TServerFrmMain.ServerExecute(AThread: TIdPeerThread);
    begin
    .
    .
    .
    AThread.Synchronize(test);
    .
    .
    .
    end;