大虾们帮忙看一下这段代码,郁闷,不知何故呀!
有两个窗体Form1, Form2;
Form2中有这样一个过程:
procedure TF_PrintLR.AutoNextRow(var QRLabelObj : TQRLabel; TextValue : String);
var
i:Integer;
tmpMemo : TMemo;
LastStr:String;
begin
tmpMemo := TMemo.Create(nil);
tmpMemo.Parent := Form2;
tmpMemo.Font:=QRLabelObj.Font;
tmpMemo.Width:=QRLabelObj.Width + 3;
tmpMemo.Text := TextValue;
for i:=0 to tmpMemo.Lines.Count-1 do
begin
LastStr := LastStr + tmpMemo.Lines[i]+ #13;
end;
QRLabelObj.Caption:=LastStr;
tmpMemo.Free;
end;
我在Form1中写了如下代码:
if Form2 = nil then
begin
try
Application.CreateForm(TForm2, Form2);
Form2.QuickRep1.PreviewModal; //<-
finally
Form2.Free;
Form2 := nil;
end;
end;
我在Form2.QuickRep1BeforePrint中写了如下代码:
if LeftOk then
begin
AutoTurnRow(QRLabel1, ContentText); //ContentText: 内容介绍
end;
当代码执行到Form2.QuickRep1.PreviewModal时,没有出现任何错误,我能看到报表,也是我想要的效果(换行),但是当试图关闭报表时,弹出错误信息:“Prject HongHo.exe raised exception class EOSError with message 'System Error. Code;1400. 无效的窗口句柄。'. Process stopped. Use Step or Run to continue.”
后来经调试发现,如果不调用 AutoTurnRow 这个过程,改用QRLabel1.Caption := '...'序程则不会出错。
奇怪的事呀,期待高手解决些问题,谢谢!