Access violation at address at delphi dll
<p>I get an error in my delphi ( XE 10 ) dll sometimes.</p>

<p>I get "Accesse violation at address" at setp 2.</p>

<blockquote>
  <p>Step2 Accesse violation at address 0AC95985 in module … Read of
  address FFFFFFFC, high(a)=31</p>
</blockquote>

<p>My delphi dll</p>

<pre><code>Library hash_sha256;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  System.SysUtils,
  System.Classes,
  System.Hash,
  Vcl.Dialogs;

{$R *.res}

function MyHash(AKey, AData: PAnsiChar): Pchar; stdcall;
var
  a: TArray&lt;byte&gt;;
  i: integer;
  s: ShortString;
begin
  try
    s:='';
    Result:='';

    try
      a:=THashSHA2.GetHMACAsBytes(String(AData), String(AKey));
    except
      on E : Exception do
         ShowMessage('Step1'+E.Message);
    end;


    try
      for i:=0 to high(a) do
        s:=s+PChar(inttohex(a[i],2));
    except
      on E : Exception do
        ShowMessage('Step2 '+E.Message+', high(a)='+IntToStr(high(a)));
    end;

    try
      Result:=Pchar(s+'');
    except
      on E : Exception do
        ShowMessage('Step3'+E.Message);
    end;

  except
    on E : Exception do
      begin
        Result:=Pchar(AnsiString(E.Message));
      end;
  end;
end;

exports MyHash name 'hash_sha256';

begin
end.
</code></pre>

<p>Who can help me ???</p>