在showReport后,点击页面设置钮并确定后总是有访问非法地址错误:(
跟踪源码发现错误发生在SetPrinter里
<pre>
procedure TfrPreviewForm.PageSetupBtnClick(Sender: TObject);
var
  psd: TPageSetupDlg;
  pg: PfrPageInfo;
  pg1: TfrPage;
  i: Integer;  procedure SetPrinter(DeviceMode, DeviceNames: THandle);
  var
    DevNames: PDevNames;
  begin
    DevNames := PDevNames(GlobalLock(DeviceNames));
    try
      with DevNames^ do // DevNames总为nil :(
//非法地址错
        Printer.SetPrinter(PChar(DevNames) + wDeviceOffset,
          PChar(DevNames) + wDriverOffset,
          PChar(DevNames) + wOutputOffset, DeviceMode);
    finally
      GlobalUnlock(DeviceNames);
      GlobalFree(DeviceNames);
    end;
  end;begin
  if EMFPages = nil then Exit;
  psd.lStructSize := SizeOf(TPageSetupDlg);
  psd.hwndOwner := ScrollBox1.Handle;
  psd.hDevMode := prn.DevMode;
  psd.hDevNames := 0;
  psd.Flags := PSD_DEFAULTMINMARGINS or PSD_MARGINS or PSD_INHUNDREDTHSOFMILLIMETERS;  pg := TfrEMFPages(EMFPages)[0];
  psd.rtMargin.Left := pg^.pgMargins.Left * 500 div 18;
  psd.rtMargin.Top := pg^.pgMargins.Top * 500 div 18;
  psd.rtMargin.Right := pg^.pgMargins.Right * 500 div 18;
  psd.rtMargin.Bottom := pg^.pgMargins.Bottom * 500 div 18;  if PageSetupDlg(psd) then
  begin
    SetPrinter(psd.hDevMode, psd.hDevNames); //psd.hDevNames总是0 
    Prn.Update;    for i := 0 to TfrReport(Doc).Pages.Count - 1 do
    begin
      pg1 := TfrReport(Doc).Pages[i];
      if pg1.PageType = ptReport then
      begin
        pg1.pgMargins.Left := psd.rtMargin.Left * 18 div 500;
        pg1.pgMargins.Top := psd.rtMargin.Top * 18 div 500;
        pg1.pgMargins.Right := psd.rtMargin.Right * 18 div 500;
        pg1.pgMargins.Bottom := psd.rtMargin.Bottom * 18 div 500;
        pg1.ChangePaper(Prn.PaperSize, 0, 0, Prn.Bin, Prn.Orientation);
      end;
    end;    TfrReport(Doc).PrepareReport;
    TfrEMFPages(EMFPages).Free;
    EMFPages := nil;
    Connect(Doc);
    RedrawAll(True);
  end;
end;
</pre>regards!