Topic: SaveToTextFile

I am using the SaveToTextFile method.  I want to include a header row, can this be achieved?

Robb

2 (edited by rjkantor 2016-03-22 17:04:42)

Re: SaveToTextFile

I am using the following commands

FrmExport.TableGrid1.SaveToTextFile(SaveDialog.Filename);

and

Frmexport.Memo1.Lines.savetofile(ExtractFileDir(SaveDialog.Filename)+'\'+'headerrow.csv');

I am then trying to concatenate the two files.  The headerrow file is showing as strange characters when concatenated with the textfile.

Are these two commands writing to the same character set?  Each file visually looks ok, but when I combine then using TFileStream the header file is not readable. See attachement https://www.dropbox.com/s/k2kzovxz1cnz6 … 6.pdf?dl=0



Thank you,
  Robb

Re: SaveToTextFile

Please attach your project.

Dmitry.

4 (edited by rjkantor 2016-03-25 16:47:03)

Re: SaveToTextFile

Sample.zip

The project generates three files:
sample_export.csv which comes from my main table
headerrow.csv which comes from the header row
fOutfile.csv which is my combined file - which does not transform nicely.

My procedure ConcatenateFiles does the final output.

Thanks for your assistance.

Re: SaveToTextFile

rjkantor
Try this procedure:

Procedure ConcatenateFiles(const InFileNames: array of string; const OutFileName: string);
var
  i: Integer;
  InStream, OutStream: TStringList;
begin

  OutStream:= TStringList.Create;
  try
    for i := 0 to length(InFileNames)-1 do
    begin
      InStream := TStringList.Create;
      InStream.LoadFromFile(InFileNames[i]);
      try
        OutStream.Text := OutStream.Text + InStream.Text;
      finally
        InStream.Free;
      end;
    end;
    OutStream.SaveToFile(OutFileName);
  finally
    OutStream.Free;
  end;

end;

Dmitry.

Re: SaveToTextFile

Thank you.  That worked.