Advertisement
Guest User

Untitled

a guest
Sep 25th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.11 KB | None | 0 0
  1. unit USyncForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.Classes, Vcl.Forms;
  7.  
  8. const
  9.   UM_MethodCall = $1400;
  10.  
  11. type
  12.   TSyncForm = class (TForm)
  13.   protected
  14.     procedure UMMethodCall (var Message: TMessage); message UM_MethodCall;
  15.  
  16.   public
  17.     procedure Synchronize (Method: TThreadMethod); overload;
  18.     procedure Synchronize (Proc: TThreadProcedure); overload;
  19.   end;
  20.  
  21. implementation
  22.  
  23. procedure TSyncForm.UMMethodCall;
  24. var
  25.   Method: TMethod;
  26. begin
  27.   if Message.LParam <> -1 then
  28.   begin
  29.     Method.Code := Pointer (Message.WParam);
  30.     Method.Data := Pointer (Message.LParam);
  31.     TThreadMethod (Method) ();
  32.   end
  33.   else
  34.   begin
  35.     TThreadProcedure (Pointer (Message.WParam)) ();
  36.   end;
  37. end;
  38.  
  39. procedure TSyncForm.Synchronize (Method: TThreadMethod);
  40. begin
  41.   SendMessage (
  42.     Handle,
  43.     UM_MethodCall,
  44.     NativeUInt (TMethod (Method).Code),
  45.     NativeInt (TMethod (Method).Data));
  46. end;
  47.  
  48. procedure TSyncForm.Synchronize (Proc: TThreadProcedure);
  49. begin
  50.   SendMessage (
  51.     Handle,
  52.     UM_MethodCall,
  53.     NativeUInt (PPointer (@Proc)^),
  54.     -1);
  55. end;
  56.  
  57. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement