Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save string to file using SaveDialog 1

Status
Not open for further replies.

chillywinter

Programmer
Apr 8, 2012
4
0
0
AU
I created a string separated by commas.

I want to save it using the savedialog but this code doesn't work:

Code:
CSV_string := '1,2,3' ;
if SaveDialog1.Execute 
  then CSV_string.savetofile(SaveDialog1.FileName + '.csv');

I've discovered that .savetofile doesn't work with strings, so how do I save a string to a file called TEST.CSV?
 
Code:
procedure SaveStringToFile(Filename : String; Str : String);
var
  FS : TFileStream;
begin
 FS := TFileStream.Create(Filename, fmCreate);
 try
  FS.Write(Str[1], Length(Str));
 finally
  FS.Free;
 end;
end;

...
if SaveDialog1.Execute
  then SaveStringToFile(SaveDialog1.FileName + '.csv', CSV_String);

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top