title: Access voilation delphi x64 with callback's
body: <p>I rewrite old code (x86 ~ 1998 year, delphi 7) on new standart (x64, Rad Studio XE 10.4). I find problem place, which stopped my work. I create minimum example, that you can debugging (The structure of the code is strictly like this!):</p>
  <pre><code>unit Unit1;
  
  interface
  
  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ShellApi;
  
  type
  TTestProc = procedure(btn: TButton; i: Integer);
  
    TForm1 = class(TForm)
      Button1: TButton;
      procedure Button1Click(Sender: TObject);
  
      procedure KeyDownTest();
      function FindNewFocused(): boolean;
      procedure Iterate(IterateProc: TTestProc);
  
    end;
  
  var
    Form1: TForm1;
  
  implementation
  
  {$R *.dfm}
  
  
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    KeyDownTest();    // --&gt;  KeyDownTest
  end;
  
  procedure TForm1.KeyDownTest();
  begin
    FindNewFocused();  // --&gt;  FindNewFocused
  end;
  
  function TForm1.FindNewFocused(): boolean;
  
    procedure IntNextVis(btn: TButton; i: Integer);
    begin
      ShowMessage(btn.Caption);  // ----&gt; ERROR: ACCESS VOILATION!
    end;
  
  begin
    Iterate(@IntNextVis); // --&gt;  Iterate
    Result := True;
  end;
  
  procedure TForm1.Iterate(IterateProc: TTestProc);
  
    procedure IntIterate(btn: TButton; i: Integer);
    begin
        if(i &gt; 2) then
          Exit;       // --&gt; break reqursive
        if(i = 2) then
          IterateProc(btn, i) // --&gt;  FindNewFocused.IntNextVis
        else
          IntIterate(btn, i + 1); // --&gt;  Iterate.IntIterate
    end;
  
  var
    i: Integer;
  begin
      i := 0;
      //ShowMessage(Button1.Caption); // ----&gt; WORKING!
      IntIterate(Button1, i);  // --&gt;  Iterate.IntIterate
  end;
  end.
  </code></pre>
  <p>On Form there is button, pressed on which on screen will be write message like: <em>Caption button</em>.
  This code working without error on x86 platform, but broken on x64 platform. I look in debugger, stack trace and dissassembler (x64 platfrom!) and find error: when app call callback procedure <code>IntNextVis(btn: TButton; i: Integer);</code>, then in asm code args callback first transmitted, and than remove! Therefore, call <code>ShowMessage(btn.Caption);</code> is an not correct, as btn will be removed. My current configuration <code>Debug</code>.
  Why that going on and how fix this bug?
  P.S.: please, tell me solution this problem without move procedure <code>IntNextVis</code> of local area of visibility from global area of visiblity, as in my old code very very very mach such codes.</p>