//把输出结果转换成文本文件
function ChangetoText(TextForm:Tform;Query1:TQuery;title:string;summary:string): Boolean;
var
I: integer;
FName,OutString: string;
OutFile: TextFile;
note: Tbookmark;
savedialog1: Tsavedialog;
begin
//创建对话框的容器
try
savedialog1 := Tsavedialog.Create(TextForm);
//Assign a filename to the variable
savedialog1.Filter := 'Text files (*.txt)|*.TXT';
if savedialog1.Execute then
FName := savedialog1.FileName+'.txt';
if FName <> '' then
begin
note := Query1.GetBookmark;
Query1.DisableControls;
//Identify the filename and type as OutFile
AssignFile(OutFile,fname);
//create and open a new file identify as OutFile
Rewrite(OutFile);
//Get text from the Query1
for I:=0 to Query1.FieldCount-1 do
begin
if query1.Fields[i].Visible = True then
begin
OutString:=OutString+Query1.Fields[i].displaylabel;
if I < Query1.FieldCount-1 then
OutString := OutString + ','
else outstring := Outstring;
end;
end;
Writeln(OutFile,OutString);
OutString := '';
While not Query1.EOF do
begin
for I:=0 to Query1.FieldCount-1 do
begin
if query1.Fields[i].Visible = True then
begin
OutString:=OutString+'"'+Query1.Fields[i].AsString+'"';
if I < Query1.FieldCount-1 then
OutString := OutString + ','
else outstring := Outstring ;
end;
end;
//Write out the text in OutString to file
Writeln(OutFile,OutString);
Query1.Next;
OutString := '';
end;
//插入总结
Writeln(OutFile,summary);
//Update and close the file
CloseFile(OutFile);
Query1.EnableControls;
Query1.GotoBookmark(note);
Query1.FreeBookmark(note);
savedialog1.Destroy;
result := True;
end;
except
CloseFile(OutFile);
Query1.EnableControls;
Savedialog1.free;
Showmessage('过程错误,请退出后重新运行!');
Result := False;
end;
end;