title: Access Violation - how do I track down the cause?
body: <p>I'm getting an access violation when I close a form in my application.  It seems to happen only after I have access a database a couple of times, but that doesn't seem to make sense.</p>
  
  <p>I have traced through and put outputdebugstring messages in all the related OnDestroy() methods, but the AV appears to be outside of my code.</p>
  
  <p>This is the text of the message:</p>
  
  <blockquote>
    <p>Access violation at address 00405F7C in module
    'MySoopaApplication.exe'. Read of address 00000008.</p>
  </blockquote>
  
  <p>How do I find where in the application 00405F7C is?</p>
  
  <p>What tools are available in Delphi 10.1 Berlin to help me with this?</p>
  
  <p>Edit: added a bit more info ... when clicking "Break" the IDE always takes me to this piece of code in GETMEM.INC:</p>
  
  <pre><code>@SmallPoolWasFull:
    {Insert this as the first partially free pool for the block size}
    mov ecx, TSmallBlockType[ebx].NextPartiallyFreePool
  </code></pre>
  
  <p>Further edit:  well, I found the culprit, though I can't honestly say that the debug tools got me there - they just seemed to indicate it wasn't in my code.</p>
  
  <p>I had used code from the net that I used to find the Windows logged in user - this is it:</p>
  
  <pre><code>function GetThisComputerName: string;
  var
    CompName: PChar;
    maxlen: cardinal;
  begin
    maxlen := MAX_COMPUTERNAME_LENGTH +1;
    GetMem(CompName, maxlen);
    try
      GetComputerName(CompName, maxlen);
      Result := CompName;
    finally
      FreeMem(CompName);
    end;
  end;
  </code></pre>
  
  <p>once I had replaced the code with a simple result := '12345' the AVs stopped.  I have no changed it to this code:</p>
  
  <pre><code>function GetThisComputerName: string;
  var
    nSize: DWord;
    CompName: PChar;
  begin
    nSize := 1024;
    GetMem(CompName, nSize);
    try
      GetComputerName(CompName, nSize);
      Result := CompName;
    finally
      FreeMem(CompName);
    end;
  end;
  </code></pre>
  
  <p>which seems to work and, as a bonus, doesn't cause AVs.</p>
  
  <p>Thanks for your help, much appreciated. </p>