Preview, Print

edited February 2019 in FastReport VCL
Hi all... [img]style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> I want use with the print button my own print procedure. Is this possible? Like a click event and nothing else.[/img][img]style_emoticons/<#EMO_DIR#>/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> Backgound: All printouts, also on the printer, are saved as PDF in a special folder. With the preview button only printing is done. Thanks...[/img]>

Comments

  • PolomintPolomint Australia
    edited February 2019
    Which edition of FastReport do you have? That is, do you have the source?

    Looking at the frxPreview.pas module, the PrintB button fires off PrintBClick.
    procedure TfrxPreviewForm.PrintBClick(Sender: TObject);
    begin
      FPreview.Print;
      Enabled := True;
    end;
    
    The code for TfrxPreview.Print then runs PreviewPages.Print:
    procedure TfrxPreview.Print;
    begin
      if FRunning then Exit;
      try
        PreviewPages.CurPreviewPage := PageNo;
        PreviewPages.Print;
      finally
        Unlock;
      end;
    end;
    
    TfrxPreview.Print looks to be the code to "override" as it is also invoked through KeyDown.
    procedure TfrxPreview.KeyDown(var Key: Word; Shift: TShiftState);
    begin
      inherited;
        :
        :
        if (Key = Ord('P')) and (pbPrint in Report.PreviewOptions.Buttons) then
          Print
        :
        :
    end;
    
    I expect your next question will be, "How do I override TfrxPreview.Print?"... [img]style_emoticons/<#EMO_DIR#>/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> Tsch??ss, Paul[/img]
  • gpigpi
    edited 12:51AM
    Print button works like open button
    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, frxClass, frxPreview, frxRes;
    
    type
      TForm1 = class(TForm)
        frxReport1: TfrxReport;
        frxPreview1: TfrxPreview;
        OpenDialog1: TOpenDialog;
        procedure frxReport1Preview(Sender: TObject);
        procedure NewOnClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      frxReport1.ShowReport();
    end;
    
    procedure TForm1.frxReport1Preview(Sender: TObject);
    begin
     if frxReport1.PreviewForm is TfrxPreviewForm then
        begin
         TfrxPreviewForm(frxReport1.PreviewForm).PrintB.OnClick := NewOnClick;
         TfrxPreviewForm(frxReport1.PreviewForm).RightMenu.Items[5].OnClick := NewOnClick;
        end;
    end;
    
    procedure TForm1.NewOnClick(Sender: TObject);
     var
     OpenDlg: TOpenDialog;
    begin
     if frxReport1.Engine.Running then Exit;
     OpenDlg := TOpenDialog.Create(nil);
     try
       OpenDlg.Options := [ofHideReadOnly];
       OpenDlg.Filter := frxResources.Get('clFP3files') + ' (*.fp3)|*.fp3';
       if OpenDlg.Execute then
       begin
         TfrxPreview(frxReport1.Preview).LoadFromFile(OpenDlg.FileName);
         frxReport1.PreviewForm.Caption := OpenDlg.FileName;
       end;
     finally
       OpenDlg.Free;
     end;
    end;
    
    end.
    
    
    end.
    
  • edited 12:51AM
    Hi... >
    wrote:
    Which edition of FastReport do you have? That is, do you have the source?
    ...without sourecode. >
    TfrxPreviewForm(frxReport1.PreviewForm).PrintB.OnClick :=
    
    ..was the answer. > But beforeShowReport the frxReport1.PreviewForm is nil.
    procedure TdmReport.frxReport1Preview(Sender: TObject);
    begin
      TfrxPreviewForm(frxReport1.PreviewForm).PrintB.OnClick := DoOnPrintButtonClick; // <--
      frxReport1.PreviewForm.Position := poDesigned;
      frxReport1.PreviewForm.OnShow := DoOnShow;
    end;
    
    ...here works.

  • PolomintPolomint Australia
    edited 12:51AM
    But before ShowReport the frxReport1.PreviewForm is nil.


    [I am having a bad day - sorry if this is a dumb question!]

    You are calling PrepareReport () somewhere in your code, before you try to print it, I assume. [img]style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> Tsch??ss, Paul[/img]
  • edited February 2019
    Hi Paul... >
    begin
      ReportFileList := TStringList.Create;
      try
        ReportFile := LoadReport(Print.ReportDocumentType);
        if FileExists(ReportFile) then
        begin
          dmReport.frxReport1.LoadFromFile(ReportFile);
          for ReportType in Print.ReportTypeList do
          begin
            case ReportType of
              rtDesign:
              begin
                dmReport.frxReport1.DesignReport;
              end;
              rtPreview:
              begin
                dmReport.OnPreviewPrintButtonClick := DoOnPreviewPrintButtonClick; // <- at this Point frxReport1.PreviewForm is nil
                dmReport.frxReport1.ReportOptions.Name := 'Vorschau';
                dmReport.frxReport1.PreviewOptions.ZoomMode := zmWholePage;
                dmReport.frxReport1.PreviewOptions.ThumbnailVisible := True;
                dmReport.frxReport1.PreviewOptions.Maximized := False;
                dmReport.frxReport1.ShowReport(True); // i use the embedded preview :-) 
              end;
              rtPrint:
              begin
                dmReport.frxReport1.PrintOptions.ShowDialog := FShowDialog; // ist Liste 1.True n?¤chsten False
                if dmReport.frxReport1.PrepareReport(True) then
                begin
                  FillReportPrint; // u.a. wegen Belegnummer f??r Event
                  if dmReport.frxReport1.Print then
                  begin
                    FShowDialog := False;
    
                    if Assigned(FOnPrintConfirmation) then
                    begin
                      FOnPrintConfirmation(Self, ReportType, Print, nil);
                    end;
                  end;
                end;
              end;
    ...
    
    i must make a extra event in the datamodule
    procedure TdmReport.DoOnPrintButtonClick(Sender: TObject);
    begin
      if Assigned(FOnPreviewPrintButtonClick) then
      begin
        FOnPreviewPrintButtonClick(Self);
      end;
    end;
    ...
    procedure TdmReport.frxReport1Preview(Sender: TObject);
    begin
      TfrxPreviewForm(frxReport1.PreviewForm).PrintB.OnClick := DoOnPrintButtonClick; // at this Point the Preview Form is valid ... with his buttons :-)
      frxReport1.PreviewForm.Position := poDesigned;
      frxReport1.PreviewForm.OnShow := DoOnShow;
    end;
    

    >

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.