W
wishme3
Unregistered / Unconfirmed
GUEST, unregistred user!
以下的程序实现将一个数据库表的数据打包成文本文件,并能在文本文件中实现数据对齐
现在的问题是:如果有多个表,分别打包成对应的文本文件,有没有理想的简洁的方法?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables;
type
TForm1 = class(TForm)
Button1: TButton;
Query1: TQuery;
Database1: TDatabase;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var F: TextFile;
h,sp,space,s,datestring: string;
senddate:Tdatetime;
Year, Month, Day: Word;
j,spacecount,i,k:integer;
begin
AssignFile(F, datestring);
Rewrite(F);
query1.close;
query1.sql.add('select * from xscj');
query1.open;
for i:=0 to query1.RecordCount-1 do
begin
space:='';
for j:=0 to query1.FieldCount-1 do
begin
sp:='';
h:=query1.fields[j].asstring;
spacecount:=query1.fields[j].datasize+2-length(h);
if SpaceCount>0 then
begin
for K:=1 to SpaceCount do
Sp :=sp+' ';
end
else
Sp := ' ';
space:=space+sp+query1.Fields[j].AsString;
end;
Writeln(F,space);
query1.next;
end;
CloseFile(F);
application.MessageBox('完成!','操作提示',0);
end;
end.
现在的问题是:如果有多个表,分别打包成对应的文本文件,有没有理想的简洁的方法?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables;
type
TForm1 = class(TForm)
Button1: TButton;
Query1: TQuery;
Database1: TDatabase;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var F: TextFile;
h,sp,space,s,datestring: string;
senddate:Tdatetime;
Year, Month, Day: Word;
j,spacecount,i,k:integer;
begin
AssignFile(F, datestring);
Rewrite(F);
query1.close;
query1.sql.add('select * from xscj');
query1.open;
for i:=0 to query1.RecordCount-1 do
begin
space:='';
for j:=0 to query1.FieldCount-1 do
begin
sp:='';
h:=query1.fields[j].asstring;
spacecount:=query1.fields[j].datasize+2-length(h);
if SpaceCount>0 then
begin
for K:=1 to SpaceCount do
Sp :=sp+' ';
end
else
Sp := ' ';
space:=space+sp+query1.Fields[j].AsString;
end;
Writeln(F,space);
query1.next;
end;
CloseFile(F);
application.MessageBox('完成!','操作提示',0);
end;
end.