title: How to free objects in stringlist in delphi 7?
body: <p>Below is the thought of Freeing Objects in Delphi's TStrings Items by  Zarko Gajic at
  at <a href="http://delphi.about.com/od/delphitips2009/qt/free-strings-objects.htm" rel="nofollow">About.com.delphi</a>  I am using Delphi 7, TStringList does not have OwnsObjects.</p>
  
  <p>Running the following code will prompt EaccessViolation error. I donot know why and how to
  walk around it to free objects.</p>
  
  <p>Thanks a lot.</p>
  
  <pre><code>procedure TForm6.freelist(const alist: TStringList);
  var
    i: integer;
  begin
    try
      for i:=0 to pred(alist.Count) do begin
        if Assigned(alist.Objects[i]) then begin
          alist.Objects[i].Free;       
          alist.objects[i]:=nil;       
        end;                           
      end;
      alist.Clear;
    finally
      alist.Free;
    end;
  end;
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>I add this line, <strong>alist.Objects[i]:=Pointer(0);</strong> and there is no error.</p>
  
  <p>...</p>
  
  <pre><code>for i:=0 to pred(alist.Count) do begin
            if Assigned(alist.Objects[i]) then begin
              alist.Objects[i]:=Pointer(0);  //newly added line. 
              alist.Objects[i].Free;       
              alist.objects[i]:=nil;       
            end;                           
          end;
  ...
  
  //But I do not know if this is correct and 
  // if the efficiency will be compromised.
  //This is awkward method?
  </code></pre>