有些是你不要的,去掉再编译吧
function ExportTXT(Query : TADOQuery; FileName : string; DateStr:string) : Boolean;
var
SaveDialog : TSaveDialog;
STRINGLIST : TStringList;
i,j,k, Row : integer;
STR,LINESTR:STRING;
begin
SaveDialog := TSaveDialog.Create(Application.MainForm);
STRINGLIST := TSTRINGLIST.Create();
SaveDialog.DefaultExt := '*.TXT';
SaveDialog.Filter := 'TXTFILE|*.TXT';
if FileName = '' then
SaveDialog.FileName := 'Export.txt'
else
SaveDialog.FileName := FileName;
//SaveDialog.FileName := 'Export.TXT';
SaveDialog.Options := [ofOverwritePrompt,ofHideReadOnly,ofEnableSizing];
if SaveDialog.Execute then
begin
FileName := SaveDialog.FileName;
Screen.Cursor := crHourGlass;
try
LINESTR:=' 日期:'+DateStr;
STRINGLIST.Add(LINESTR);
LINESTR:='';
if not Query.Active then
begin
Query.Open;
end;
Query.first;
for i := 0 to Query.Fields.Count - 1 do
BEGIN
if Query.Fields.Visible then
begin
STR:=Query.Fields.DisplayLabel;
k:=query.Fields.DataSize+2 ;
if k<32 then k:=32;
// for j:=query.Fields.datasize to query.Fields.DataSize+2 do
for j:=Length(STR) to k do
begin
str:=str+' ';
end;
LINEStr:=LINESTR+STR+chr(9);
end;
end;
STRINGLIST.Add(LINESTR);
while not Query.Eof do
begin
LINESTR:='';
for i := 0 to Query.Fields.Count - 1 do
begin
if Query.Fields.Visible then
begin
STR:=Query.Fields.AsString;
if (query.Fields.IsNull) or ( Trim(query.Fields.AsString)='') then str:='';
trim(str);
if (Length(trim(str)) >= 10) then
if IsNumber(Str) then str:=chr(1)+STR; //Insert('''',Str,1);
//防止身份证记为科学记数法
if Query.Fields.DataType = ftDateTime then
begin
if Query.Fields.AsDateTime = 0 then
str := ''
else
begin
str := FormatDateTime((Query.Fields as TDateTimeField).displayformat, Query.Fields.AsDateTime);
end;
end;
k:=query.Fields.DataSize+2 ;
if k<32 then k:=32;
//for j:=query.Fields.datasize to query.Fields.datasize+2 do
for j:=Length(STR) to k do
begin
str:=str+' ';
end;
LINEStr:=LINESTR+STR+chr(9);
end // if Query.Fields.Visible then
end; //end for i := 0 to Query.Fields.Count - 1 do
STRINGLIST.Add(LINESTR);
Query.Next;
end;
STRINGLIST.SaveToFile(SaveDialog.FileName);
Screen.Cursor := crDefault;
Application.MessageBox('Export successfully!', 'Information', 0);
finally
SaveDialog.Free;
STRINGLIST.Free;
end;
end;
end;