Delphi 曾经有过 foreach 循环吗?

发布于 2024-08-29 18:55:21 字数 443 浏览 11 评论 0原文

我读到 Delphi 应该在 Delphi 9 中获得一个 for every 循环。这个功能是否已经融入到该语言中了?我的 Delphi 2009 IDE 似乎无法识别 foreach 语法。这是我的代码:

  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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不寐倦长更 2024-09-05 18:55:21
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; 
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; 
浊酒尽余欢 2024-09-05 18:55:21

是的。

但这是for..in

尝试一下

var
  s: string;
  c: char;

begin
  s:=' Delphi Rocks!';
  for c in s do  //<--- here is the interesting part
  begin
    Application.MainForm.Caption:=Application.MainForm.Caption+c;
    Sleep(400); //delay a little to see how it works
  end;

Yes.

But it is for..in

Try

var
  s: string;
  c: char;

begin
  s:=' Delphi Rocks!';
  for c in s do  //<--- here is the interesting part
  begin
    Application.MainForm.Caption:=Application.MainForm.Caption+c;
    Sleep(400); //delay a little to see how it works
  end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文