QuickReport中动态创建TQRLabel时出错!!! ( 积分: 100 )

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

zjmaskman

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位大侠,我下面的代码哪里有错呢?每次走完这个过程后,就出错说读内存中的某个地址时出错,跟踪QuickReport的源代码发现动态创建的这几个QRLabel的QRPrinter为nil,导致在调用TCustomLabel.Print方法时,无法使用QRPrinter.Canvas属性造成。那我该怎样解决呢?救救我啊.......
procedure TQuickRep1.DetailBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
var i:integer;
Labels:array of TQRLabel;
begin
SetLength(Labels,3);
for i:=0 to 2do
begin
Labels := TQRLabel.Create(Sender);
with TQRLabel(Labels)do
begin
Name := 'laDate' + inttostr(i+1);
Parent := Sender;
Left := 10 * (i+1);
Width := 20;
Height := 14;
ParentFont := True;
Visible := True;
Enabled := True;
Caption := 'OK';
end;
end;
end;
 
请问各位大侠,我下面的代码哪里有错呢?每次走完这个过程后,就出错说读内存中的某个地址时出错,跟踪QuickReport的源代码发现动态创建的这几个QRLabel的QRPrinter为nil,导致在调用TCustomLabel.Print方法时,无法使用QRPrinter.Canvas属性造成。那我该怎样解决呢?救救我啊.......
procedure TQuickRep1.DetailBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
var i:integer;
Labels:array of TQRLabel;
begin
SetLength(Labels,3);
for i:=0 to 2do
begin
Labels := TQRLabel.Create(Sender);
with TQRLabel(Labels)do
begin
Name := 'laDate' + inttostr(i+1);
Parent := Sender;
Left := 10 * (i+1);
Width := 20;
Height := 14;
ParentFont := True;
Visible := True;
Enabled := True;
Caption := 'OK';
end;
end;
end;
 
段纯动态创建,找对你有用的来:
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i:integer;
leftx:integer;
widthperbyte:integer;
Heading:TQRlabel;
QRLabel: TQRlabel;
QRshape1: TQRshape;
QRshape2: TQRshape;
QRdbtext: TQRDBtext;
qrexpr :TQRExpr ;
begin

widthperbyte:=10;
columnswidth;
disposecontrols;
if totalwidth*widthperbyte>1123 then
begin
Application.MessageBox('±¨±í3??í,??μ÷???ùê?3?£?','?ˉ??',1);//ê?3????°?ò
exit;
end
else
if totalwidth*widthperbyte>794 then
unit2.Form2.QuickRep1.Page.Orientation:=polandscape //oá?ò
else
unit2.Form2.QuickRep1.Page.Orientation:=poPortrait;//×Y?ò
Heading:=TQRlabel.Create(self);
//′′?¨TQRlabel???t
Heading.parent:=unit2.Form2.TitleBand1;
//éè????èY?÷???t
Heading.Caption:='?§éú??3ì3é?¨±í';
//±¨±í±êìa
Heading.Font.Size:=16;
Heading.Font.Style:=[fsbold];
Heading.Alignment:=tacenter;
Heading.Width:=Length('?§éú??3ì3é?¨±í')*(widthperbyte+4);
Heading.Left:=(unit2.Form2.QuickRep1.Width-Heading.width)div 2;
Heading.Height:=unit2.Form2.TitleBand1.Height -1 ;
Heading.Top:=0;

Leftx:=(unit2.Form2.quickrep1.width-totalwidth*widthperbyte)div 2;
for i:=0 to Listbox2.items.count-1do
//?ù?Y?ù????×???μ?êy??à′?ˉì?′′?¨
begin
QRShape1:=TQRSHape.Create(self);
QRShape1.parent:=unit2.Form2.ColumnHeaderBand;
QRShape1.Left:=Leftx;
QRShape1.Width:=maxwidth*widthperbyte+4;
QRShape1.Height:=unit2.Form2.ColumnHeaderBand.Height;
QRShape1.top:=0;
QRLabel:=TQRLabel.Create(self);
QRLabel.parent:=unit2.Form2.ColumnHeaderBand;
QRLabel.Font.Style:=[fsbold];
QRLabel.Left:=Leftx+2;
QRLabel.width:=maxwidth*widthperbyte;
QRLabel.height:=unit2.Form2.ColumnHeaderBand.Height;
QRLabel.top:=1;
QRLabel.caption:=Listbox2.Items.Strings;

QRShape2:=TQRSHAPE.Create(self);
QRShape2.Parent:=unit2.Form2.DetailBand1;
QRShape2.Left:=Leftx ;
QRShape2.Width:=maxwidth*widthperbyte+4;
QRShape2.Height:=unit2.Form2.DetailBand1.Height ;
QRShape2.top:=0;

QRDBText:=TQRDBText.Create(self);
QRDBText.parent:=unit2.Form2.DetailBand1;
QRDBText.Left:=Leftx+2;
QRDBText.Width:=maxwidth*widthperbyte;
QRDBText.Height:=unit2.Form2.DetailBand1.Height -2;
QRDBText.Top:=1;
QRDBText.DataSet:=unit1.Form1.ADOQuery1;
QRDBText.DataField:=Listbox2.Items.Strings;
Leftx:=Leftx+maxwidth*widthperbyte+4;
end;
qrexpr:=TQRexpr.Create(self);

qrexpr.Left:=10;
unit2.Form2.QuickRep1.PreviewModal;
end;

procedure disposecontrols;
var i:integer;
begin
for i:=0 to unit2.Form2.TitleBand1.ControlCount-1do
//è????μí3?????tμ?????
unit2.Form2.TitleBand1.RemoveControl(unit2.Form2.TitleBand1.Controls[0]);
for i:=1 to unit2.Form2.ColumnHeaderBand.ControlCountdo

unit2.Form2.ColumnHeaderBand.RemoveControl(unit2.Form2.ColumnHeaderBand.Controls[0]);
for i:=1 to unit2.Form2 .DetailBand1.ControlCount do
unit2.Form2.DetailBand1.RemoveControl(unit2.Form2.DetailBand1.Controls[0]);

end;
 
接受答案了.
 
后退
顶部