0

Name Address1 Address2 Addess3
---------------- --------------------- -------------------- -------------------
Name1 Address1 Address2 Address3
Name2 Address1 (NULL) Address3
Name3 Address1 Address2 (NULL)

I need to take this information and export it into a CSV file with the Owners Address (combination of add1, add2 and add3) As a single string, Then take the Town.. which could either be (Add2, or Add3)
Writing it to the end of the whole (Owner+Address) String As well as within it.

Here I have the information being exported into a CSV file, But am unsure as how to proceed with adding the Town again at the end of the owner string.

procedure SaveAsCSV(myFileName: string; myDataSet: TDataSet);
var
  Owner: TextFile;
  i: integer;
  s: string;
begin
  AssignFile (Owner, myFileName);
  Rewrite(Owner);

  s := '';

  try

    for i := 0 to myDataSet.FieldCount - 1 do
      begin
        s := s + Format('"%s";', [myDataSet.Fields[i].FieldName]);
      end;
    Writeln(Owner, s);


    while not myDataSet.Eof do
      begin
        s := '';
        for i := 0 to myDataSet.fieldCount -1 do
          begin
            s := s + Format('"%s";', [myDataSet.Fields[i].AsString]);
          end;
        Writeln(Owner, s);
        myDataSet.Next;
      end;
  finally
    CloseFile(Owner);
  end;
end;

procedure TForm1.OutputClick(Sender: TObject);
begin
  DBGrid1.Visible := False;
  try
    if (SaveDialog1.Execute = true) and
     (length(SaveDialog1.FileName) > 0) then
      begin
        SaveDialog1.DefaultExt := 'CSV';
        SaveAsCSV(SaveDialog1.Filename, SQLQuery1);
      end;
  finally
    DBGrid1.Visible := True;
  end;
end;
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by BitFarmer
0

The code you supplie DOESN'T do what you claim, it export each field in a separate row, don't mix any number of rows into a single one anyhow... so adding the town at the end is not the problem herte... isn't it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.