【问题标题】:How do I run multiple commands in an if-then-else statement?如何在 if-then-else 语句中运行多个命令?
【发布时间】:2014-03-19 14:46:07
【问题描述】:

我怎样才能在 delphi 7 中做这样的事情

if FileExists
    then 
        Filesetattr
        DownloadFile
    else
        Downloadfile
        Filesetattr

我试过 ;它不工作。 我尝试使用逗号(,)也不起作用。 所以我希望在一个“then 语句”中执行两个或多个命令,在“else 语句”中执行两个或多个命令

【问题讨论】:

  • if Condition then begin DoSome; Stuff; end else begin DoSome; OtherStuff; end; 但这些是您在学习 Pascal/Delphi 时应该逐步完成的基础知识。
  • 你用哪本书来学习Delphi?它应该很早就告诉你了。
  • 你应该看看this answer你的问题;o)

标签: delphi if-statement syntax


【解决方案1】:

如果你想让if语句控制多行,用begin end包围

if FileExists
  then 
  begin
    Filesetattr;
    DownloadFile;
  end
  else
    begin
      Downloadfile;
      Filesetattr;
    end;

【讨论】:

  • 这里的布局很不寻常。我从来没有见过像这样布置的真正代码。
  • @DavidHeffernan,那是我通常按 Ctrl-D 的地方
  • Delphi 不关心布局/格式。该代码仍然 100% 有效。给我点赞。
猜你喜欢
  • 1970-01-01
  • 2013-03-05
  • 2019-01-30
  • 2021-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多