Mega Code Archive

 
Categories / Delphi / ADO Database
 

The function DatasetToInfFile

Title: The function DatasetToInfFile Question: How to save the content of a table (or dataset) into a text file ? Answer: These small functions are parsing a table and write the contents into a TStringList. Than it's easy to save this into a file. procedure DatasetRecordToInfFile(aDataset: TDataSet; aStrList: TStrings); var i: integer; begin for i := 0 to (aDataset.FieldCount-1) do aStrList.Add(aDataset.Fields[i].FieldName + '=' + aDataset.Fields[i].AsString); end; procedure DatasetToInfFile(aDataset: TDataSet; aStrList: TStrings); begin aDataSet.First; while not aDataSet.EOF do begin DatasetRecordToInfFile(aDataset,aStrList); aDataSet.Next; end; end; procedure TForm1.Button1Click(Sender: TObject); begin DatasetRecordToInfFile(Table1,Memo1.Lines); end; procedure TForm1.Button2Click(Sender: TObject); begin DatasetToInfFile(Table1,Memo1.Lines); end;