QuickReport动态加载lab Dbtext的问题函数里的循环运行第2次就异常了,附全部代码。 ( 积分: 7 )

  • 主题发起人 主题发起人 handsome1234
  • 开始时间 开始时间
H

handsome1234

Unregistered / Unconfirmed
GUEST, unregistred user!
QuickReport动态加载lab Dbtext的问题函数里的循环运行第2次就异常了,附全部代码
我只实现了基本功能,但是也不该出错阿?
在Qrs_PubFrm_Printer里面调用QRSDbCreate
QRSLabelFix是固定格式的,需要放倒Headband上的标示符
QRSDBTextFix

QRLabelList和QRDBTextLists是需要放倒Detailband上的,是由实参传递多少个字段来动态决定生成多少个。
现在的问题是我得程序在执行QRSDbCreate这个函数里当执行第2个循环时
QRShapeListHead.parent:=ColumnHeaderBand1;//这里报异常AV
不理解,还望个为高手帮忙。

unit Qrs_Pub_Frm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, DB, DBTables, QRCtrls,StdCtrls,StrUtils;
type
TQrs_Form_Pub = class(TForm)
QuickRep1: TQuickRep;
ColumnHeaderBand1: TQRBand;
DetailBand1: TQRBand;
PageFooterBand1: TQRBand;
PageHeaderBand1: TQRBand;
SummaryBand1: TQRBand;
public

function QRSDbCreate(QRLabelList: array of TQRLabel;QRDBTextList: array of TQRDBText;QRShapeListHead,QRShapeListDetail: array of TQRShape;ColumnHeaderBand1,DetailBand1:TQRBand;StringList,StringListDB:TStringList): boolean;
function CreateFix(QRSLabelFix: array of TQRLabel;QRSDBTextFix: array of TQRDBText; ColumnHeaderBand1, DetailBand1: TQRBand;LabNum,DbNum:integer): boolean;
function Qrs_PubFrm_Printer(Dataset:TDataset;StringList,StringListDB:TStringList;Str_Kind,Str_Title:String;WhetherPreview:Boolean ):Boolean ;
end;

var
Qrs_Form_Pub: TQrs_Form_Pub;
function ShowQrs_PubFrm(): Boolean;

implementation

{$R *.dfm}
var
PrintStringLabel,PrintStringLabelDB:TStringList;

function ShowQrs_PubFrm(): Boolean;
begin
Qrs_Form_Pub:=TQrs_Form_Pub.Create(Application);
// Qrs_PubFrm.Hide;
Qrs_Form_Pub.Release;
end;
{ TQrs_Form_Pub }

function TQrs_Form_Pub.CreateFix(QRSLabelFix: array of TQRLabel;QRSDBTextFix: array of TQRDBText; ColumnHeaderBand1, DetailBand1: TQRBand;LabNum,DbNum:integer): boolean;
var
i:integer;
begin
for i :=0 to LabNum do
begin
QRSLabelFix:=TQRLabel.Create(Self);
if i<=1 then
QRSLabelFix.Parent := ColumnHeaderBand1
else
QRSLabelFix.Parent := SummaryBand1;//ppSummaryBand1;
end;
for i :=0 to DbNum do
begin
QRSDBTextFix:=TQRDBText.Create(Self);
QRSDBTextFix.Parent := ColumnHeaderBand1;//有可能是其他值 客户或单号
end;
end;

function TQrs_Form_Pub.QRSDbCreate(QRLabelList: array of TQRLabel;
QRDBTextList: array of TQRDBText; QRShapeListHead,
QRShapeListDetail: array of TQRShape; ColumnHeaderBand1,
DetailBand1: TQRBand; StringList, StringListDB: TStringList): boolean;

var
i:integer;
begin

for i:=0 to StringList.Count-1 do
begin
QRShapeListHead:=TQRShape.Create(Application);
QRShapeListHead.parent:=ColumnHeaderBand1;//这里报异常AV
QRShapeListHead.Shape:=qrsVertLine;
QRShapeListDetail:=TQRShape.Create(Application);
QRShapeListDetail.parent:=DetailBand1;
QRShapeListDetail.Shape:=qrsVertLine;

QRLabelList:=TQRLabel.Create(Application);
QRLabelList.parent:=ColumnHeaderBand1; //ColumnHeaderBand1;
QRDBTextList:=TQRDBText.Create(Application);
QRDBTextList.parent:=DetailBand1; //ColumnHeaderBand1;

case StrToInt(RightStr(StringListDB,(Length(StringListDB)- pos('A',StringListDB)))) of
1:
begin
QRLabelList.Width:=80;
QRDBTextList.Width:=QRLabelList.Width;
end ;
2:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
3:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
4:
begin
QRLabelList.Width:=25;
QRDBTextList.Width:=QRLabelList.Width;
end ;
5:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
6:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
7:
begin
QRLabelList.Width:=120;
QRDBTextList.Width:=QRLabelList.Width;
end ;
8:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
9:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
10:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
11:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
12:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
end;

if i=0 then
begin
QRLabelList.Left:=0;
QRLabelList.Height:=30;
QRDBTextList.Left:=0;
QRDBTextList.Height:=30;
end
else
begin
QRLabelList.Left:=QRLabelList[i-1].Left+QRDBTextList[i-1].Width;
QRLabelList.Height:=25;
QRLabelList.Top:=24;//24是留给第几页的。
QRLabelList.Caption:=StringList.Strings;//QRLabelList.Frame.
QRDBTextList.Left:=QRLabelList[i-1].Left+QRDBTextList[i-1].Width;
QRDBTextList.Height:=25;
end;
end;

end;

function TQrs_Form_Pub.Qrs_PubFrm_Printer(Dataset: TDataset; StringList,
StringListDB: TStringList;Str_Kind,Str_Title:String; WhetherPreview: Boolean): Boolean;
var
i,k:integer;
LabNum, DbNum: integer;
Str_Title_Real:String;
QRShapeListHead,QRShapeListDetail: array of TQRShape;
QRLabelList: array of TQRLabel ;
QRDBTextList: array of TQRDBText;
QRSLabelFix: array of TQRLabel;
//单号、日期、数量合计、金额合计,负责人、保管、业务、开票、客户、经手人
QRSDBTextFix: array of TQRDBText;
//单号、日期、客户
HeadofTQRShape:TQRShape;
SelectedFields : TStringlist;
SrcList: TCustomListBox;
begin
Str_Title_Real:=Str_Title;//传递标题
Setlength(QRSLabelFix,10);
Setlength(QRSDBTextFix,3);
CreateFix(QRSLabelFix,QRSDBTextFix,ColumnHeaderBand1, DetailBand1,10,3);
Qrs_Form_Pub.QuickRep1.DataSet:=Dataset;
Setlength(QRLabelList ,StringList.Count);
Setlength(QRDBTextList ,StringListDB.Count);
Setlength(QRShapeListHead,StringListDB.Count);
Setlength(QRShapeListDetail,StringListDB.Count);
QRSDbCreate(QRLabelList,QRDBTextList,QRShapeListHead,QRShapeListDetail,ColumnHeaderBand1,DetailBand1, StringList, StringListDB);
try
Qrs_Form_Pub.QuickRep1.Preview;
finally
Qrs_Form_Pub.table1.close;
SelectedFields.free;
end;
end;
end.
 
QuickReport动态加载lab Dbtext的问题函数里的循环运行第2次就异常了,附全部代码
我只实现了基本功能,但是也不该出错阿?
在Qrs_PubFrm_Printer里面调用QRSDbCreate
QRSLabelFix是固定格式的,需要放倒Headband上的标示符
QRSDBTextFix

QRLabelList和QRDBTextLists是需要放倒Detailband上的,是由实参传递多少个字段来动态决定生成多少个。
现在的问题是我得程序在执行QRSDbCreate这个函数里当执行第2个循环时
QRShapeListHead.parent:=ColumnHeaderBand1;//这里报异常AV
不理解,还望个为高手帮忙。

unit Qrs_Pub_Frm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, DB, DBTables, QRCtrls,StdCtrls,StrUtils;
type
TQrs_Form_Pub = class(TForm)
QuickRep1: TQuickRep;
ColumnHeaderBand1: TQRBand;
DetailBand1: TQRBand;
PageFooterBand1: TQRBand;
PageHeaderBand1: TQRBand;
SummaryBand1: TQRBand;
public

function QRSDbCreate(QRLabelList: array of TQRLabel;QRDBTextList: array of TQRDBText;QRShapeListHead,QRShapeListDetail: array of TQRShape;ColumnHeaderBand1,DetailBand1:TQRBand;StringList,StringListDB:TStringList): boolean;
function CreateFix(QRSLabelFix: array of TQRLabel;QRSDBTextFix: array of TQRDBText; ColumnHeaderBand1, DetailBand1: TQRBand;LabNum,DbNum:integer): boolean;
function Qrs_PubFrm_Printer(Dataset:TDataset;StringList,StringListDB:TStringList;Str_Kind,Str_Title:String;WhetherPreview:Boolean ):Boolean ;
end;

var
Qrs_Form_Pub: TQrs_Form_Pub;
function ShowQrs_PubFrm(): Boolean;

implementation

{$R *.dfm}
var
PrintStringLabel,PrintStringLabelDB:TStringList;

function ShowQrs_PubFrm(): Boolean;
begin
Qrs_Form_Pub:=TQrs_Form_Pub.Create(Application);
// Qrs_PubFrm.Hide;
Qrs_Form_Pub.Release;
end;
{ TQrs_Form_Pub }

function TQrs_Form_Pub.CreateFix(QRSLabelFix: array of TQRLabel;QRSDBTextFix: array of TQRDBText; ColumnHeaderBand1, DetailBand1: TQRBand;LabNum,DbNum:integer): boolean;
var
i:integer;
begin
for i :=0 to LabNum do
begin
QRSLabelFix:=TQRLabel.Create(Self);
if i<=1 then
QRSLabelFix.Parent := ColumnHeaderBand1
else
QRSLabelFix.Parent := SummaryBand1;//ppSummaryBand1;
end;
for i :=0 to DbNum do
begin
QRSDBTextFix:=TQRDBText.Create(Self);
QRSDBTextFix.Parent := ColumnHeaderBand1;//有可能是其他值 客户或单号
end;
end;

function TQrs_Form_Pub.QRSDbCreate(QRLabelList: array of TQRLabel;
QRDBTextList: array of TQRDBText; QRShapeListHead,
QRShapeListDetail: array of TQRShape; ColumnHeaderBand1,
DetailBand1: TQRBand; StringList, StringListDB: TStringList): boolean;

var
i:integer;
begin

for i:=0 to StringList.Count-1 do
begin
QRShapeListHead:=TQRShape.Create(Application);
QRShapeListHead.parent:=ColumnHeaderBand1;//这里报异常AV
QRShapeListHead.Shape:=qrsVertLine;
QRShapeListDetail:=TQRShape.Create(Application);
QRShapeListDetail.parent:=DetailBand1;
QRShapeListDetail.Shape:=qrsVertLine;

QRLabelList:=TQRLabel.Create(Application);
QRLabelList.parent:=ColumnHeaderBand1; //ColumnHeaderBand1;
QRDBTextList:=TQRDBText.Create(Application);
QRDBTextList.parent:=DetailBand1; //ColumnHeaderBand1;

case StrToInt(RightStr(StringListDB,(Length(StringListDB)- pos('A',StringListDB)))) of
1:
begin
QRLabelList.Width:=80;
QRDBTextList.Width:=QRLabelList.Width;
end ;
2:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
3:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
4:
begin
QRLabelList.Width:=25;
QRDBTextList.Width:=QRLabelList.Width;
end ;
5:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
6:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
7:
begin
QRLabelList.Width:=120;
QRDBTextList.Width:=QRLabelList.Width;
end ;
8:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
9:
begin
QRLabelList.Width:=60;
QRDBTextList.Width:=QRLabelList.Width;
end ;
10:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
11:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
12:
begin
QRLabelList.Width:=40;
QRDBTextList.Width:=QRLabelList.Width;
end ;
end;

if i=0 then
begin
QRLabelList.Left:=0;
QRLabelList.Height:=30;
QRDBTextList.Left:=0;
QRDBTextList.Height:=30;
end
else
begin
QRLabelList.Left:=QRLabelList[i-1].Left+QRDBTextList[i-1].Width;
QRLabelList.Height:=25;
QRLabelList.Top:=24;//24是留给第几页的。
QRLabelList.Caption:=StringList.Strings;//QRLabelList.Frame.
QRDBTextList.Left:=QRLabelList[i-1].Left+QRDBTextList[i-1].Width;
QRDBTextList.Height:=25;
end;
end;

end;

function TQrs_Form_Pub.Qrs_PubFrm_Printer(Dataset: TDataset; StringList,
StringListDB: TStringList;Str_Kind,Str_Title:String; WhetherPreview: Boolean): Boolean;
var
i,k:integer;
LabNum, DbNum: integer;
Str_Title_Real:String;
QRShapeListHead,QRShapeListDetail: array of TQRShape;
QRLabelList: array of TQRLabel ;
QRDBTextList: array of TQRDBText;
QRSLabelFix: array of TQRLabel;
//单号、日期、数量合计、金额合计,负责人、保管、业务、开票、客户、经手人
QRSDBTextFix: array of TQRDBText;
//单号、日期、客户
HeadofTQRShape:TQRShape;
SelectedFields : TStringlist;
SrcList: TCustomListBox;
begin
Str_Title_Real:=Str_Title;//传递标题
Setlength(QRSLabelFix,10);
Setlength(QRSDBTextFix,3);
CreateFix(QRSLabelFix,QRSDBTextFix,ColumnHeaderBand1, DetailBand1,10,3);
Qrs_Form_Pub.QuickRep1.DataSet:=Dataset;
Setlength(QRLabelList ,StringList.Count);
Setlength(QRDBTextList ,StringListDB.Count);
Setlength(QRShapeListHead,StringListDB.Count);
Setlength(QRShapeListDetail,StringListDB.Count);
QRSDbCreate(QRLabelList,QRDBTextList,QRShapeListHead,QRShapeListDetail,ColumnHeaderBand1,DetailBand1, StringList, StringListDB);
try
Qrs_Form_Pub.QuickRep1.Preview;
finally
Qrs_Form_Pub.table1.close;
SelectedFields.free;
end;
end;
end.
 
后退
顶部