【问题标题】:Save a real number to a text file Delphi将实数保存到文本文件 Delphi
【发布时间】:2014-08-19 12:28:18
【问题描述】:

我正在处理一个文本文件 Waiterstips. 文本文件如下所示:

34.12;45.54;67.99;23.01;99.50;15.14;96.12;
65;67;89;45;00.00;15.23;12.15;00.00;95.32;
87;87;65;97;41.25;36.58;96.14;78.88;11.01;
67;54;57;37;00.00;00.00;10.20;05.00;12.41;

When I use the code below the text file look like this:
10.00;45.54;67.99;23.01;99.50;15.14;96.12
65.00;67.00;89.00;12.50;10.00;15.23;12.15
87.00;87.00;65.00;97.00;41.25;36.58;96.14
67.00;54.00;57.00;50.12;10.00;10.00;10.20
;;;;;;

请帮助我想保存数据,就像我读入时一样。我不想要;;;;最后。

procedure TForm1.BitBtn2Click(Sender: TObject);
var
  fFile : TextFile;
  iCount : Integer;
begin
  AssignFile(fFile, 'Waiterstips.txt');
  Rewrite(fFile);
  For iCount := 1 to StringGrid1.RowCount - 1 do
  begin
    Writeln(fFile, StringGrid1.Cells[1,iCount]+ ';'+ StringGrid1.Cells[2,iCount]+ ';' +
    StringGrid1.Cells[3,iCount]+ ';' +StringGrid1.Cells[4,iCount]+ ';' +StringGrid1.Cells[5,iCount]
    + ';' +StringGrid1.Cells[6,iCount]+ ';'+StringGrid1.Cells[7,iCount]+ ';');
  end;
  CloseFile(fFile);

end;

【问题讨论】:

    标签: delphi delphi-xe6


    【解决方案1】:

    显然您的TStringGrid 末尾有一个空白行。

    您可以通过在写出之前检查行内容来修复它:

        for iCount := 1 to StringGrid1.RowCount - 1 do
        begin
          if StringGrid1.Cells[1, iCount] <> '' then
            WriteLn(fFile, StringGrid1.Cells[1, iCount] + ';' +
                           StringGrid1.Cells[2, iCount] + ';' +
                          .....
        end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 2011-08-06
      • 2021-08-18
      • 2021-12-13
      • 2016-10-28
      • 1970-01-01
      • 2012-08-10
      相关资源
      最近更新 更多