自己摸索一下 RMReport1.SaveReportOptions.AutoLoadSaveSetting := True; RMReport1.SaveReportOptions.UseRegistry := False; RMReport1.SaveReportOptions.IniFileName := 'S:\rm.ini';//和每个报表文件一一对应 //下面这行FileName 一定要加,而且在LoadFromFile 前面
//原因是,程序运行,首次执行LoadFromFile,其调用LoadFromStream, 在LoadFromStream的最后部分会调用 FSaveReportOptions.LoadReportSetting(Self, '', False);
这时FFileName的值是'Untitled'。
而LoadFromFile 中在调用LoadFromStream(lStream);后才会设置 文件名。FileName := aFileName;
所以,必须 在 LoadFromFile 前 先设置FileName值。
RMReport1.FileName := 'd:\mydoc\桌面\测试背景图片.rmf'; RMReport1.LoadFromFile('d:\mydoc\桌面\测试背景图片.rmf'); RMReport1.ShowReport; 或者 RMReport1.PrintReport; 这样无论是先预览 再点击工具栏的打印按钮 还是 直接打印 ,最后的打印对话框上,都会显示 过去调试的 打印偏移值。 要把 模版导出到 其他电脑,或者 相同电脑的其他文件夹 内容使用。 只要复制2个文件,*.rm 和 *.ini
: 男 lynu (lynu) ▲▲▲▲▲ - 盒子活跃会员 2014-4-23 22:18:44 1楼: 这个我看过源码,PrepareReport会将PrintOffset归零的. 如果你不动手改rm源码,可以在 reportObj.PrepareReport; //放在这里才有效 setoffset; reportObj.PrintPreparedReport
procedure TRMReport.OnTimerPrepareReportEvent(Sender: TObject); begin FTimer.Enabled := False; while FCurPreview = nil do Application.ProcessMessages; PrepareReport;//这里,好像是线程准备报表 end;
procedure TRMReport.ShowReport;// var lSaveThreadFlag: Boolean; // tmp: DWORD; begin if FBusy then Exit; if FTimer = nil then begin FTimer := TTimer.Create(nil); with FTimer do begin Enabled := False; Interval := 10; OnTimer := OnTimerPrepareReportEvent;// end; end;
procedure _RestoreReport; var i: Integer; lSaveErrorFlag: Boolean; lSaveErrorMsg: string; lStream: TMemoryStream; lReport: TRMReport; begin lSaveErrorFlag := ErrorFlag; lSaveErrorMsg := ErrorMsg; try if Self is TRMCompositeReport then begin for i := 0 to TRMCompositeReport(Self).Reports.Count - 1 do begin lStream := lReportList[i]; lStream.Position := 0; lReport := TRMReport(TRMCompositeReport(Self).Reports[i]); if Assigned(lReport.FOnEndDoc) then lReport.FOnEndDoc(lReport); lReport.LoadFromStream(lStream); end; end else begin lStream := lReportList[0]; lStream.Position := 0; LoadFromStream(lStream);//这里 第二次调用 end; finally for i := 0 to lReportList.Count - 1 do begin TMemoryStream(lReportList[i]).Free; end; lReportList.Free; lReportList := nil; ErrorFlag := lSaveErrorFlag; ErrorMsg := lSaveErrorMsg; end; end;
TRMReport.PrepareReport 。。。 finally // if ErrorFlag then // EndPages.Clear; if (FCurPreview <> nil) then begin THackPreview(FCurPreview).EndPrepareReport(Self, FThreadPrepareReport); end else if FPreview <> nil then begin THackPreview(FPreview).EndPrepareReport(Self, False); end; FreeProgressForm; _RestoreReport;
procedure TRMReport.LoadFromStream(aStream: TStream); var lPos: Integer; lStr: string; begin ConvertNulls := False; RMCurReport := Self; ErrorFlag := False; ErrorMsg := ''; FDocMode := rmdmDesigning; Clear; if aStream.Size < 10 then Exit; lStr := RMReadString(aStream); if (lStr <> RM_ReportFlagStr + #26) and (lStr <> RM_ReportFlagStr1 + #26) then begin ErrorFlag := True; ErrorMsg := 'Not ReportMachine Report File!'; Application.MessageBox(PChar(RMLoadStr(SNotRMFFile)), PChar(RMLoadStr(SError)), mb_Ok + mb_IconError); Pages.Clear; Pages.AddReportPage; Exit; end; FReportVersion := RMReadWord(aStream); if FReportVersion > RMCurrentVersion then begin Application.MessageBox(PChar(RMLoadStr(SRMFError)), PChar(RMLoadStr(SError)), mb_Ok + mb_IconError); Exit; end; if FReportVersion > 51 then begin RMReadWord(aStream); // HVersion lPos := RMReadInt32(aStream); end else lPos := 0; ReportInfo.Title := RMReadString(aStream); ReportInfo.Author := RMReadString(aStream); ReportInfo.Company := RMReadString(aStream); ReportInfo.CopyRight := RMReadString(aStream); ReportInfo.Comment := RMReadString(aStream); FColorPrint := RMReadBoolean(aStream); FmmPrintOffsetTop := RMReadInt32(aStream); FmmPrintOffsetLeft := RMReadInt32(aStream); FmmPrintOffsetTop := 0;//这里先读取后 又自己清0了 FmmPrintOffsetLeft := 0; FPageCompositeMode := TRMCompositeMode(RMReadByte(aStream)); PrintBackGroundPicture := RMReadBoolean(aStream); DoublePass := RMReadBoolean(aStream); PrinterName := RMReadString(aStream); if FReportVersion >= 65 then RMReadWideMemo(aStream, FScript) else FScript.Text := RMReadAnsiMemo(aStream); if FReportVersion > 51 then begin FReportFlags := RMReadWord(aStream); if FReportVersion >= 57 then ConvertNulls := RMReadBoolean(aStream); aStream.Position := lPos; end else begin FReportFlags := 0; AutoSetPageLength := False; end; try Pages.LoadFromStream(FReportVersion, aStream); except on E: EClassNotFound do Application.MessageBox(PChar('Opened report contains the following non-plugged components:' + #13 + E.Message + 'Use appropriate component from RM component palette'), PChar(RMLoadStr(SError)), mb_Ok + mb_IconError); else end; FSaveReportOptions.LoadReportSetting(Self, '', False);//读取报表文件外的设置 if FReportVersion < 64 then FPageCompositeMode := rmReportPerReport; end;