unit QueryExport;
interface
uses
Windows, Messages, SysUtils, Classes,
DB, DBTables;
type
TQueryExport = class(TQuery)
private
{ Private-Deklarationen }
fExportFile: String;
fSeperator: String;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
procedure ExportAsCsv;
published
{ Published-Deklarationen }
property ExportFile: String read fExportFile write fExportFile;
property Seperator: String read fSeperator write fSeperator;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Beispiele', [TQueryExport]);
// RegisterComponents('Specialwork Database', [TQueryExport]);
end;
procedure TQueryExport.ExportAsCsv;
var
ExportedStrings: TStringList;
Y: Integer;
CurrentDataset: String;
begin
ExportedStrings:=TStringList.Create;
try
try
if Active then begin
while not Eof do begin
CurrentDataset:='';
for Y:=0 to Fields.Count-1 do begin
CurrentDataset := CurrentDataset + Fields[y].AsString;
CurrentDataset := CurrentDataset + Seperator;
end;
ExportedStrings.Add(CurrentDataset);
Next;
end;
end;
ExportedStrings.SaveToFile(ExportFile);
except
on E:
Exception do begin
OutputDebugString(PChar(E.Message));
end;
end;
finally
ExportedStrings.Free;
end;
end;
end.