title: Why does deleting a TStringList pointer throw an exception?
body: <p>I am using Embarcadero C++ Builder.</p>
  
  <p>I have a function that declares a <code>TStringList</code>, uses it throughout the function, then <code>delete</code>s the object at the end of the function.</p>
  
  <p>I have been using this code happily as a 32 bit application and have converted it to a 64 bit application, and now I get an "Invalid Pointer Operation" exception when trying to delete the <code>TStringList</code>.  Any ideas?</p>
  
  <p>The odd thing is I had the same trouble with another function that uses a character pointer (using <code>new</code> to create heap memory space) and a <code>delete</code> operation.  I ended up creating a local buffer with stack space for that function, but I'm stuck with this one since I would like to use the <code>TStringList</code> object.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>String ReadUserConfig(String ConfigString) {
      String UserConfigPath = AppDrive + "\\DC\\userconfig.csv";
  
      TStringList *List = new TStringList;
  
  
      if (FileExists(UserConfigPath)) { // file present, parse it
          try {
              List-&gt;LoadFromFile(UserConfigPath);
              delete List;
          }
          catch(...) {
              ShowMessage("Exception in ReadUserConfig()");
              return ReturnString;
          }
          for (int i = 0; i &lt; List-&gt;Count; ++i) {
              String thisLine = List-&gt;Strings[i];
  
              /* search for ConfigString in this line */
              if ((thisLine.Pos(ConfigString) != 0) &amp;&amp;
                  (thisLine.Pos("USER_CONFIG") != 0)) {
                  /* grab everything right of ConfigString */
                  thisLine = thisLine.SubString
                      (thisLine.Pos(ConfigString) + ConfigString.Length() + 1,
                      thisLine.Length());
                  ReturnString = thisLine.Trim();
  
                  i = List-&gt;Count;
              }
          }
  
      }
  
      delete List;  /* CAUSES INVALID POINTER EXCEPTION */
      return ReturnString;
  }
  </code></pre>