The best way to sync is to create and use a TidNotify descendant.
Define the tidnotify child and vcl proc, like this, with the corresponding private fields.
TVclProc= procedure(aBMP: TBitmap) of object; TBmpNotify = class(TIdNotify) protected FBMP: TBitmap; FProc: TVclProc; procedure DoNotify; override; public constructor Create(aBMP: TBitmap; aProc: TVclProc); reintroduce; class procedure NewBMP(aBMP: TBitmap; aProc: TVclProc); end;
then we implement it as follows
{ TBmpNotify } constructor TBmpNotify.Create(aBMP: TBitmap; aProc: TVclProc); begin inherited Create; FBMP:= aBMP; FProc:= aProc; end; procedure TBmpNotify.DoNotify; begin inherited; FProc(FBMP); end; class procedure TBmpNotify.NewBMP(aBMP: TBitmap; aProc: TVclProc); begin with Create(aBMP, aProc) do begin Notify; end; end;
then from
server.execute(...)
name it like that
procedure TTCPServer.DoExecute(aContext: TIdContext); var NewBMP: TBitmap; begin TBmpNotify.NewBMP(NewBMP, FVclBmpProc); end;
If FVclBmpProcis is a private field that points to a procedure in a form that matches the signature of the TVclProc parameter. This field must be set via a property on the server object immediately after creation and before starting the server.
the method in the form will be free to use the resulting bitmap without fear of thread conflicts, deadlock and other nasty things created by accessing VCL controls without synchronization.
Miket source share