thread SynchronizeEx method
Return to Introduction  Previous page  Next page
Applies to
auThread component.  

Declaration
procedure SynchronizeEx(Method: TNotifyEvent; Params: Pointer);  

Description
The SynchronizeEx method executes a method call within the main VCL thread. Synchronize causes the call specified by Method to be executed using the main VCL thread, thereby avoiding multi-thread conflicts. If you are unsure whether a method call is thread-safe, call it from within the main VCL thread by passing it to the Synchronize or SynchronizeEx methods.  
 
Internally, the SynchronizeEx works exactly like Synchronize, but allows to tramsmit additional parameters (Params) to the synchronized method. See example below.  
 
tip Execution of the thread is suspended while Method is executing in the main VCL thread.  

Example
type  
  TForm1 = class(TForm)  
    auThread1: TauThread;  
    procedure auThread1Execute(Sender: TObject);  
  private  
    procedure SyncCall(Sender: TObject);  
  public  
  end;  
 
implementation  
 
type  
  PMyData = ^TMyData;  
  TMyData = record  
    I: Integer;  
    S: String;  
  end;  
 
procedure TForm1.auThread1Execute(Sender: TObject);  
var  
  Data: TMyData;  
begin  
  // -- snip --  
  with Data do  
   begin  
    S := 'some text';  
    I := Random(100); // some number  
   end;  
  auThread1.SynchronizeEx(SyncCall, @Data);  
  // -- snip --  
end;  
 
procedure TForm1.SyncCall(Sender: TObject);  
begin  
  with PMyData(Sender)^ do  
   begin  
    // Here you getting access to the parameters  
    // described in TMyData structure. Example:  
    Application.MessageBox(PChar(S), PChar(IntToStr(I)), MB_OK);  
   end;  
end;  

See also
Synchronize, Execute, Suspend, Resume and Terminate methods.