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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memo to CSV

Status
Not open for further replies.

dforce13

Programmer
Sep 15, 2008
6
BE
In my program I let things see in een TMemo.
Now my question is how to save these things in a CSV file ?
 
That is a pretty general question.

A CSV file is nothing more than a bunch of lines (aka "records") which are subdivided (into "fields") by commas.

Code:
type
  tEmployee = record
              surname:    string;
              given_name: string;
              pay_rate:   double;
              hire_date:  tDateTime;
              ...
              end;

procedure write_CSV_record( var f: textfile; var e: tEmployee );
  begin
  Write( f, e.surname,      ', ' );
  Write( f, e.given_name,   ', ' );
  Write( f, e.pay_rate:0:4, ', ' );
  Write( f, FormatDateTime( 'yyyy-mm-dd', e.hire_date ), ', ' );
  ...
  Writeln( f )
  end;

procedure write_CSV_file( var f: textfile; var es: array of tEmployee );
  var n: cardinal;
  begin
  for n := 0 to high( es ) do
    write_CSV_record( f, es[ n ] )
  end;

Hope this helps get you going.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top