Reputation: 17
I am working with a text file Waiterstips. The text file look like this:
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
;;;;;;
Please help I want to save the data the same as when I read it in. I dont want the ;;;; at the end.
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;
Upvotes: 0
Views: 181
Reputation: 125689
Apparently you have a blank row at the end in your TStringGrid
.
You can fix it by checking the row content before you write it out:
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;
Upvotes: 4