type DispCallBackProc=procedure (var LineNo,TotalLineCount:integer;var ConvBytes:int64) of object;
const DispInterval=1000;
var BreakConvert:Boolean=false;
Function DataSetToASCII1(const ADataSet: TDataSet;
const ASCIIFile: TFileName;
const Delimiter: Char=',';
const QuoteStrings: Boolean=false;DispFp
ispCallBackProc=nil):Boolean;
const MaxLineBufSize=8192;
var
TmpList: TFileStream;
i, LastIndex: LongInt;
AsciiRecord: PChar;
LineCount,TotalLine,LineNo:integer;
ConvSize:int64;
procedure AppendBuf(const S:string);
var len:integer;
begin
len:=length(s);
Move(S[1],AsciiRecord[LineCount],len);
inc(LineCount,len);
inc(ConvSize,len);
end;
begin
Result:=false;
try
TmpList:=TFileStream.Create(ASCIIFile,fmcreate or fmShareDenyNone);
except
ShowMessage('Could not save table to specified file: ' + ASCIIFile)
end;
try
AsciiRecord:=StrAlloc(MaxLineBufSize);
with ADataSet do
begin
DisableControls();
TotalLine:=RecordCount;
LastIndex := Fields.Count - 1;
First;
LineNo:=0;
while (not BreakConvert) And (not EOF) do
begin
LineCount:=0;
for i := 0 to LastIndex do
if Fields
.Tag = 0 then
begin
if QuoteStrings and
(Fields.DataType in [ftString, ftMemo, ftFmtMemo, ftFixedChar, ftWideString]) then
begin
AppendBuf('''');
AppendBuf(Fields.AsString);
AppendBuf('''');
end else
AppendBuf(Fields.AsString);
if i < LastIndex then
AppendBuf(Delimiter);
end;
TmpList.Write(AsciiRecord^,LineCount);
TmpList.Write(#13#10,2);
inc(ConvSize,2);
inc(LineNo);
if Assigned(DispFp) then
if Lineno mod DispInterval=0 then
DispFp(LineNo,TotalLine,ConvSize);
Application.ProcessMessages();
Next;
end ;
end;
Result:=not BreakConvert;
finally
AdataSet.EnableCOntrols();
TmpList.Free;
StrDispose(AsciiRecord);
end;
end;