【问题标题】:Pascal Progress Status帕斯卡进度状态
【发布时间】:2017-01-30 16:49:29
【问题描述】:

我正在尝试在 free pascal 中模拟进度加载状态,但我在尝试实现看起来像加载进度状态的输出时遇到了困难。 我的代码是:

percent := 0;
Writeln('Loading');   
Repeat
 Write('(',percent,'%)');
 percent = percent + 1;
 Delay(50);
Until percent > 100;

但是输出结果是这样的:

Loading(0%)(1%)(2%)

当我希望它看起来像这样时:

Loading(0%) -> Loading(1%) {The percent variable going up like a loading status}

我只希望百分比变量在循环中改变。我已经查看了删除和插入过程,但我认为这不是我想要的。

【问题讨论】:

标签: freepascal


【解决方案1】:

您需要使用退格键返回并重新写入。像这样:

uses Crt;
var percent: integer;
begin
  percent := 0;
  Write('Loading ');
  Repeat
   Write('(',percent:3,'%)'#8#8#8#8#8#8);
   percent := percent + 1;
   Delay(50);
  Until percent > 100;
end.

【讨论】:

  • 谢谢!正是我想要的
  • @LeCarloVC 还有几个技巧:1)写回车(CR)不换行(LF):Write(#13); Write('(',percent,'%)'); 2)使用VT100 Escape sequencesWrite(#27'[5D'); {Move cursor left 5 positions} Write('(',percent,'%)');PS:不确定是不是与 Windows CMD 兼容。 PPS:您可以使用来自SysUtils 单位的Sleep,而不是来自CrtDelay
猜你喜欢
  • 1970-01-01
  • 2017-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多