用过QRPreview的高手进来帮看看,难道没有人会吗?还有就算是用quickrep.preview里面那个打印也不能打印,为什么? ( 积分: 50 )

  • 主题发起人 主题发起人 zzz_222
  • 开始时间 开始时间
Z

zzz_222

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是三个单元的代码,为什么在unit3里按那个打印按钮(红字部分)打印不了呢?而将蓝字部分不要就能打印呢?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
mi:integer;

implementation

uses unit2,unit3;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
mi:=0;
form2.QuickRep1.Preview;
form2.Free;
end;

procedure TForm1.FormShow(Sender: TObject);
var i,j:byte;
begin
for i:=0 to stringgrid1.ColCount-1 do
for j:=0 to stringgrid1.RowCount-1 do
stringgrid1.Cells[i,j]:=inttostr(i+j);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
form2.QuickRep1.Print;
end;

end.

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QRCtrls, QuickRpt, ExtCtrls, QRPrntr;

type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRBand2: TQRBand;
QRLabel1: TQRLabel;
QRBand3: TQRBand;
QRSysData1: TQRSysData;
procedure FormCreate(Sender: TObject);
procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
procedure QuickRep1Preview(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses unit1,unit3;

var myqrl:array[1..100] of Tqrlabel;

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
var s:integer;
begin
for s:=1 to 100 do begin
Myqrl:=TQrlabel.Create(qrband2);
with Myqrl do begin
Parent:=qrband2;
Left:=(s-1)*50+8;
Top:=4;
alignment:=tacenter;
font.Size:=10;
font.Name:='宋体';
enabled:=false;
Caption:='';
end;
end;
end;

[blue]procedure TForm2.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
var s,j:byte;
begin
s:=form1.StringGrid1.ColCount;
for j:=1 to s do begin
myqrl[j].Enabled:=true;
myqrl[j].Caption:=form1.StringGrid1.Cells[j-1,mi];
end;
inc(mi);
MoreData:=(mi<form1.StringGrid1.RowCount+1);
end;[/blue]

procedure TForm2.QuickRep1Preview(Sender: TObject);
begin
with Tform3.Create(Application) do
begin
QRPreview1.QRPrinter := TQRPrinter(Sender);
show;
end;
end;

end.

unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, QRPrntr;

type
TForm3 = class(TForm)
QRPreview1: TQRPreview;
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

{$R *.dfm}

[red]procedure TForm3.Button1Click(Sender: TObject);
begin
QRPreview1.QRPrinter.Print;
end;[/red]

end.
 
以下是三个单元的代码,为什么在unit3里按那个打印按钮(红字部分)打印不了呢?而将蓝字部分不要就能打印呢?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
mi:integer;

implementation

uses unit2,unit3;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
mi:=0;
form2.QuickRep1.Preview;
form2.Free;
end;

procedure TForm1.FormShow(Sender: TObject);
var i,j:byte;
begin
for i:=0 to stringgrid1.ColCount-1 do
for j:=0 to stringgrid1.RowCount-1 do
stringgrid1.Cells[i,j]:=inttostr(i+j);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
form2.QuickRep1.Print;
end;

end.

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QRCtrls, QuickRpt, ExtCtrls, QRPrntr;

type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRBand2: TQRBand;
QRLabel1: TQRLabel;
QRBand3: TQRBand;
QRSysData1: TQRSysData;
procedure FormCreate(Sender: TObject);
procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
procedure QuickRep1Preview(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses unit1,unit3;

var myqrl:array[1..100] of Tqrlabel;

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
var s:integer;
begin
for s:=1 to 100 do begin
Myqrl:=TQrlabel.Create(qrband2);
with Myqrl do begin
Parent:=qrband2;
Left:=(s-1)*50+8;
Top:=4;
alignment:=tacenter;
font.Size:=10;
font.Name:='宋体';
enabled:=false;
Caption:='';
end;
end;
end;

[blue]procedure TForm2.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
var s,j:byte;
begin
s:=form1.StringGrid1.ColCount;
for j:=1 to s do begin
myqrl[j].Enabled:=true;
myqrl[j].Caption:=form1.StringGrid1.Cells[j-1,mi];
end;
inc(mi);
MoreData:=(mi<form1.StringGrid1.RowCount+1);
end;[/blue]

procedure TForm2.QuickRep1Preview(Sender: TObject);
begin
with Tform3.Create(Application) do
begin
QRPreview1.QRPrinter := TQRPrinter(Sender);
show;
end;
end;

end.

unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, QRPrntr;

type
TForm3 = class(TForm)
QRPreview1: TQRPreview;
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

{$R *.dfm}

[red]procedure TForm3.Button1Click(Sender: TObject);
begin
QRPreview1.QRPrinter.Print;
end;[/red]

end.
 
--form2.Free;
上面这一句可能不合适,form2估计是自动创建的窗体,不需要手动释放.
另外,form3中的QRPriview没有Create,这么运行是不是出现了非法访问0x00000000的错误?
 
问题是蓝字部分不要的话就能打印,什么原因呢
 
OnNeedData好像是对应于DataSet是否设置,以及DetailBand的,很久没用了。

如果是非数据库赋值,可以在BeforePrint里完成。
 
接受答案了.
 

Similar threads

后退
顶部