title: Translate a code using pointer, to Assembly in Pascal - Delphi
body: <p>I have this code below, and I want to translate it to ASM, to use in Delphi too.</p>
  
  <pre><code>var
      FunctionAddressList: Array of Integer;
  
  type TFunction = function(parameter: Integer): Integer; cdecl;
  
  function Function(parameter: Integer): Integer;
  var
      ExternFunction: TFunction;
  begin
      ExternFunction := TFunction(FunctionAddressList[5]);
      Result := ExternFunction(parameter);
  end;
  </code></pre>
  
  <p>It works normaly, but when I try its Assembly version:</p>
  
  <pre><code>function Function(parameter: Integer): Integer; cdecl;
  asm
    mov eax, FunctionAddressList
    jmp dword ptr [eax + 5 * 4]
  end;
  </code></pre>
  
  <p>It is supposed to work, because, in C++ it works in both ways:</p>
  
  <pre><code>void *FunctionAddressList;
  
  _declspec(naked) int Function(int parameter)
  {
      _asm mov eax, FunctionAddressList;
      _asm jmp dword ptr [eax + 5 * 4];
  }
  
  typedef int (*TFunction)(int parameter);
  int Function(int parameter)
  {
      TFunction ExternFunction = ((TFunction *)FunctionAddressList)[5];
      return ExternFunction(parameter);
  }
  </code></pre>
  
  <p>But it doesn't work in Delphi.</p>
  
  <p>In the Assembly version, it multiplies the array to 4, because it's the offset size between each element of the array, so both versions are equivalent.</p>
  
  <p>So, I want to know why it doesn't work with Delphi. In Delphi, the offset size between Integer values in a array is different than C++?</p>
  
  <p>I've already tried many offsets, as 1, 2, 4, 6, 8, etc. And many types of Array (Array of Pointer; only Pointer; Array of Integer, etc), and I've tried many calling conventions, and cdecl was the only that worked with the non-asm version, but with ASM, all the tests didn't work.</p>
  
  <p>Thanks.</p>