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;