title: Passing a method's code as an argument in a typesafe way
body: <p>Passing a method as an argument is not a problem:</p>
  
  <pre><code>type
    TSomething = class
      Msg: string;
      procedure Show;
    end;
  
  procedure TSomething.Show;
  begin
    ShowMessage(Msg);
  end;
  
  type TProc = procedure of object;
  
  procedure Test(Proc: TProc);
  begin
    Proc;
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  var
    Smth: TSomething;
  
  begin
    Smth:= TSomething.Create;
    Smth.Msg:= 'Hello';
    Test(Smth.Show);
  end;
  </code></pre>
  
  <p>I need something tricky - to pass only a code part of a method. I know I can do it:</p>
  
  <pre><code>procedure Test2(Code: Pointer);
  var
    Smth: TSomething;
    Meth: TMethod;
  
  begin
    Smth:= TSomething.Create;
    Smth.Msg:= 'Hello Hack';
    Meth.Data:= Smth;
    Meth.Code:= Code;
    TProc(Meth);
    Smth.Free;
  end;
  
  procedure TForm1.Button2Click(Sender: TObject);
  begin
    Test2(@TSomething.Show);
  end;
  </code></pre>
  
  <p>but that is a hack and unsafe - the compiler can't check the method's arguments.</p>
  
  <p>The question: Is it possible to do the same in a typesafe way?</p>