帮我分析这段代码,执行时正常,程序一关闭,就出错了。procedure TForm_sysmodel1rep.RepInit(myDS: TDataSet; s_title: string);
var
i,icount,isumsize,ilabelleft,ishapeleft:integer;
sizepercent:real; //缩放比率
begin
if myds.IsEmpty then
begin
application.MessageBox(pchar('数据不存在! '),'提示信息',mb_OK+mb_Iconquestion);
exit;
end;
QRLabel_title.Caption:=s_title;
QuickRep1.DataSet:=myds; icount:=myds.FieldCount-1;
setlength(myQRLabel,icount);
setlength(myQRDBText,icount);
setlength(myQRShape,icount*2);
isumsize:=0;
for i := 0 to icount do
isumsize:=isumsize+myds.Fields[i].DisplayWidth ;
sizepercent:=ColumnHeaderBand1.Width / isumsize;
ilabelleft:=0;
ishapeleft:=0;
for i:=0 to icount do
begin
if i=0 then ilabelleft:=6 else ilabelleft:=ilabelleft+round(6+myds.Fields[i-1].DisplayWidth*sizepercent);
myqrlabel[i]:=TQRLabel.Create(ColumnHeaderBand1);
myqrlabel[i].Parent := ColumnHeaderBand1;
myqrlabel[i].Top := 34;
myqrlabel[i].Left := ilabelleft;
myqrlabel[i].Caption := myds.Fields[i].DisplayName ; myQRDBText[i]:=TQRDBText.Create(DetailBand1);
myQRDBText[i].Parent := DetailBand1;
myQRDBText[i].Top := 8;
myQRDBText[i].Left := ilabelleft;
myQRDBText[i].DataSet := myds;
myQRDBText[i].DataField := myds.Fields[i].FieldName ; ishapeleft:= ishapeleft+round(3+myds.Fields[i].Size*sizepercent);
if i<icount then
begin
myQRShape[2*i]:=TQRShape.Create(ColumnHeaderBand1);
myQRShape[2*i].Parent := ColumnHeaderBand1;
myQRShape[2*i].Top := 25;
myQRShape[2*i].Left :=ishapeleft;
myQRShape[2*i].Width :=1;
myQRShape[2*i].Height :=35;
myQRShape[2*i].Pen.Color := clGreen; myQRShape[2*i+1]:=TQRShape.Create(DetailBand1);
myQRShape[2*i+1].Parent := DetailBand1;
myQRShape[2*i+1].Top := -1;
myQRShape[2*i+1].Left := ishapeleft;
myQRShape[2*i+1].Width :=1;
myQRShape[2*i+1].Height :=35;
myQRShape[2*i+1].Pen.Color := clGreen;
end;
end;
end;
报这个错 Invalid pointer operation
我不知道为什么,哪位大虾帮我改进一下这段代码,或者提一些思路。
请看不懂的人,不要回贴说废话。
var
i,icount,isumsize,ilabelleft,ishapeleft:integer;
sizepercent:real; //缩放比率
begin
if myds.IsEmpty then
begin
application.MessageBox(pchar('数据不存在! '),'提示信息',mb_OK+mb_Iconquestion);
exit;
end;
QRLabel_title.Caption:=s_title;
QuickRep1.DataSet:=myds; icount:=myds.FieldCount-1;
setlength(myQRLabel,icount);
setlength(myQRDBText,icount);
setlength(myQRShape,icount*2);
isumsize:=0;
for i := 0 to icount do
isumsize:=isumsize+myds.Fields[i].DisplayWidth ;
sizepercent:=ColumnHeaderBand1.Width / isumsize;
ilabelleft:=0;
ishapeleft:=0;
for i:=0 to icount do
begin
if i=0 then ilabelleft:=6 else ilabelleft:=ilabelleft+round(6+myds.Fields[i-1].DisplayWidth*sizepercent);
myqrlabel[i]:=TQRLabel.Create(ColumnHeaderBand1);
myqrlabel[i].Parent := ColumnHeaderBand1;
myqrlabel[i].Top := 34;
myqrlabel[i].Left := ilabelleft;
myqrlabel[i].Caption := myds.Fields[i].DisplayName ; myQRDBText[i]:=TQRDBText.Create(DetailBand1);
myQRDBText[i].Parent := DetailBand1;
myQRDBText[i].Top := 8;
myQRDBText[i].Left := ilabelleft;
myQRDBText[i].DataSet := myds;
myQRDBText[i].DataField := myds.Fields[i].FieldName ; ishapeleft:= ishapeleft+round(3+myds.Fields[i].Size*sizepercent);
if i<icount then
begin
myQRShape[2*i]:=TQRShape.Create(ColumnHeaderBand1);
myQRShape[2*i].Parent := ColumnHeaderBand1;
myQRShape[2*i].Top := 25;
myQRShape[2*i].Left :=ishapeleft;
myQRShape[2*i].Width :=1;
myQRShape[2*i].Height :=35;
myQRShape[2*i].Pen.Color := clGreen; myQRShape[2*i+1]:=TQRShape.Create(DetailBand1);
myQRShape[2*i+1].Parent := DetailBand1;
myQRShape[2*i+1].Top := -1;
myQRShape[2*i+1].Left := ishapeleft;
myQRShape[2*i+1].Width :=1;
myQRShape[2*i+1].Height :=35;
myQRShape[2*i+1].Pen.Color := clGreen;
end;
end;
end;
报这个错 Invalid pointer operation
我不知道为什么,哪位大虾帮我改进一下这段代码,或者提一些思路。
请看不懂的人,不要回贴说废话。
而且你的是对象数组,更是需要手工释放掉它所占的内存的了
for i:= Low(myQrShape) to High(myQrShapge) do
begin
myQrShape[i].Free;
myQrShape[i] := nil;
end;
var bm_display:tbook;
begin
if Query_main.IsEmpty then begin
application.messagebox('数据不存在!','提示',mb_ok+mb_iconerror);
abort;
end;
try
Application.CreateForm(TForm_sysmodel1rep, Form_sysmodel1rep);
bm_display:=Query_main.GetBook;
Form_sysmodel1rep.RepInit(Query_main,self.Caption);
Form_sysmodel1rep.QuickRep1.previewmodal;
Query_main.GotoBook(bm_display);
Query_main.FreeBook(bm_display);
Form_sysmodel1rep.RepFreeObject;
Form_sysmodel1rep.Release;
except
end;
end;
按照你的要求,在报表窗口,增加了下面的方法:
procedure TForm_sysmodel1rep.RepFreeObject;
var i:integer;
begin
for i:= Low(myQrShape) to High(myQrShape) do
begin
myQrShape[i].Free;
myQrShape[i] := nil;
end;
for i:= Low(myQRLabel) to High(myQRLabel) do
begin
myQRLabel[i].Free;
myQRLabel[i] := nil;
end;
for i:= Low(myQRDBText) to High(myQRDBText) do
begin
myQRDBText[i].Free;
myQRDBText[i] := nil;
end;
end;依然出现访问错误,Invalid pointer operation
我调试过,都不出错,只是关闭的时候,就出错了。