有代码的:
一共有两个窗体,其中一个为报表:
form1的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADODataSet1: TADODataSet;
ADOConnection1: TADOConnection;
GroupBox1: TGroupBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
Button3: TButton;
Button4: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if edit1.text= '' then
showmessage('姓名栏未填写')
else
if edit2.text='' then
showmessage('部门栏未填写')
else
if edit3.text='' then
showmessage('职务栏未填写')
else
if edit4.text='' then
showmessage('编号栏未填写')
else
begin
with ADODataSet1do
begin
Append;
FieldByName('xinming').AsString:=Edit1.Text;
FieldByName('bumen').AsString:=Edit2.Text;
FieldByName('zhiwu').AsString:=Edit3.Text;
FieldByName('bianhao').AsString:=Edit4.Text;
// FieldByName('dayin').Asboolean:=flase;
Post;
ShowMessage('数据已经保存!!');
end;
edit1.text :='';
edit2.text :='';
edit3.text :='';
edit4.text :='';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
QuickReport2.preview;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if ADODataSet1.recordcount=0 then
showmessage('没有数据可以打印,请检查你的输入')
else
QuickReport2.print;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.
Qreport代码:
unit Unit2;
interface
uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
StdCtrls, ExtCtrls, Forms, Quickrpt, QRCtrls, Db;
type
TQuickReport2 = class(TQuickRep)
DetailBand1: TQRBand;
QRDBText1: TQRDBText;
QRDBText3: TQRDBText;
QRDBText4: TQRDBText;
QRDBText5: TQRDBText;
procedure QuickRepAfterPrint(Sender: TObject);
private
public
end;
var
QuickReport2: TQuickReport2;
implementation
uses Unit1;
{$R *.DFM}
procedure TQuickReport2.QuickRepAfterPrint(Sender: TObject);
begin
// with Form1.ADODataSet1do
// begin
// last;
// while not Form1.ADODataSet1.bofdo
// begin
// delete;
// end;
// end;
end;
end.
谢谢!