第二个问题的另一个解:
把只需预览时显示不需要打印的对象的Tag属性定义为一个负数,如-1,然后用下面的代码替换原程序中的相应部分就可以了:
function notprint(frReport1:tfrReport):boolean;
//处理不需打印的对象
var
i,j:integer;
begin
for j:=0 to frreport1.Pages.Count-1do
for i:=0 to frReport1.Pages[j].Objects.count-1do
if strtointdef(TfrView(frReport1.Pages[j].Objects).tag,0)<0 then
TfrView(frReport1.Pages[j].Objects).Visible:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
//打印
begin
frReport1.LoadFromFile('c:/1.frf');
notprint(frReport1);
frReport1.PrepareReport;
frReport1.PrintPreparedReport('',1,True,frAll);
end;
procedure TForm1.Button2Click(Sender: TObject);
//预览
begin
frReport1.LoadFromFile('c:/1.frf');
frReport1.ShowReport;
end;