Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit USyncForm;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.Classes, Vcl.Forms;
- const
- UM_MethodCall = $1400;
- type
- TSyncForm = class (TForm)
- protected
- procedure UMMethodCall (var Message: TMessage); message UM_MethodCall;
- public
- procedure Synchronize (Method: TThreadMethod); overload;
- procedure Synchronize (Proc: TThreadProcedure); overload;
- end;
- implementation
- procedure TSyncForm.UMMethodCall;
- var
- Method: TMethod;
- begin
- if Message.LParam <> -1 then
- begin
- Method.Code := Pointer (Message.WParam);
- Method.Data := Pointer (Message.LParam);
- TThreadMethod (Method) ();
- end
- else
- begin
- TThreadProcedure (Pointer (Message.WParam)) ();
- end;
- end;
- procedure TSyncForm.Synchronize (Method: TThreadMethod);
- begin
- SendMessage (
- Handle,
- UM_MethodCall,
- NativeUInt (TMethod (Method).Code),
- NativeInt (TMethod (Method).Data));
- end;
- procedure TSyncForm.Synchronize (Proc: TThreadProcedure);
- begin
- SendMessage (
- Handle,
- UM_MethodCall,
- NativeUInt (PPointer (@Proc)^),
- -1);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement