Did Delphi ever get a for each loop?

Ryan picture Ryan · Apr 19, 2010 · Viewed 43.5k times · Source

I've read that Delphi was supposed to get a for each loop in Delphi 9. Did this functionality ever make it into the language? My Delphi 2009 IDE doesn't seem to recognize the for each syntax. Here's my code:

  procedure ProcessDirectory(p_Directory, p_Output : string);
  var
    files : TStringList;
    filePath : string;
  begin
    files := GetSubfiles(p_Directory);
    try
      for (filePath in files.Strings) do
      begin
        // do something
      end;

    finally
      files.Free;
    end;
  end;

Answer

da-soft picture da-soft · Apr 19, 2010
procedure ProcessDirectory(p_Directory, p_Output : string); 
var 
  files : TStringList; 
  filePath : string; 
begin 
  files := GetSubfiles(p_Directory); 
  try 
    for filePath in files do 
    begin 
      // do something 
    end; 

  finally 
    files.Free; 
  end; 
end;