QuickReport??™s expression in FastReport

edited 6:52PM in FastReport 4.0
Hello,

Before I was using ???QuickReport??? to design my reports. I am just new to FastReport.

I will like to build reports using FastReport 4.13.2 for Delphi XE5. I could not find the appropriate chapter in help-documentation that addresses the issue below.


In the QuickReport, I can write this code: QRLabel1.Caption: = 'Some text'. How can I use FastReport to do so in TfrReport.OnBefore event?

Any help and enlightenment about this issue will be highly appreciated. Thanks.

Regards,
Alex


Ps:
In other words, what is the equivalent of below expression in FastReport?


procedure TTarjous1.QuickRep1BeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
QRTarjous1Toimitusehto.caption:=F_main_LSF.ToimitusehtoEdit.text; //An Edit:Variables of the type "String" from the Main Form
QRTarjous1hintaan.caption:=FloatToStrF(F_main_LSF.CalculatedValue,ffNumber,15,0)+' ??¬'; //Variable of the type "Double" converted to String
QRTarjous1Lasinleveys.caption:=F_main_LSF.Saler2B.text+' mm'; //An Edit

QR_Rs_Name.caption := Optioner.Rs_Name; //Variables of the type "String" from Unit "Optioner"
QR_Rs_Address.caption := Optioner.Rs_Address;
end;

Comments

  • edited 6:52PM
    In FastReport, you can use TfrxMemoView.

    QR: QRLabel1.Caption := 'some text'; //*Delphi code
    FR: frxMemoView1.Memo.Text := 'here, too.'; //*FastScript code

    And...
    If you want to assign some event handlers in FastReport, you do by same way of Delphi.

    sample code:
    //In Delphi
    procedure TMainForm.PrintReport(const APreview: Boolean);
    begin
      //set FastReport variable
      frxReport1.Variables['TextVar1'] := '''' + ToimitusehtoEdit.Text + ''''; //*IMPORTANT* if you use string variables, quote by '.
      frxReport1.Variables['TextVar2'] := '''' + FloatToStrF(CalculatedValue,ffNumber,15,0) + '  ??¬' + '''';
      frxReport1.Variables['TextVar3'] := '''' + Saler2B.text + '  mm' + '''';
      frxReport1.Variables['TextVar4'] := '''' + Optioner.Rs_Name + '''';
      frxReport1.Variables['TextVar5'] := '''' + Optioner.Rs_Address + '''';
    
      //execute print or preview
      if APreview then
      begin
        frxReport1.ShowReport;
      end
      else
      begin
        frxReport1.PrepareReport;
        frxReport1.Print;
      end;
    end;
    
    
    //In FastReport
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    begin
      frxMemoViewTarjous1Toimitusehto.Memo.Text := <TextVar1>;    //An Edit:Variables of the type "String" from the Main Form
      frxMemoViewTarjous1hintaan.Memo.Text      := <TextVar2>;    //Variable of the type "Double" converted to String
      frxMemoViewTarjous1Lasinleveys.Memo.Text  := <TextVar3>;    //An Edit
    
      frxMemoViewRs_Name.Memo.Text              := <TextVar4>;    //Variables of the type "String" from Unit "Optioner"
      frxMemoViewRs_Address.Memo.Text           := <TextVar5>;
    end;
    
  • edited 6:52PM
    In FastReport, you can use TfrxMemoView.

    QR: QRLabel1.Caption := 'some text'; //*Delphi code
    FR: frxMemoView1.Memo.Text := 'here, too.'; //*FastScript code


    Hi,

    I am unable to comply the code following your suggestion and enlightenment herein.

    The name of the memo in frxReport1 is
    Memo3: TFrxMemoView

    ERROR
    E2003 Undeclared identifier: frxMemoViewMemo3

    What is wrong in my code (see below)? I using FastReport 4.13.2 for Delphi XE5.

    Regards,
    Alex

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, frxClass, frxExportImage,
      frxExportRTF, frxExportPDF;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        frxReport1: TfrxReport;
        frxRTFExport1: TfrxRTFExport;
        frxBMPExport1: TfrxBMPExport;
        frxJPEGExport1: TfrxJPEGExport;
        frxGIFExport1: TfrxGIFExport;
        frxPDFExport1: TfrxPDFExport;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure frxReport1BeforePrint(Sender: TfrxReportComponent);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    frxReport1.ShowReport;
    end;
    
    procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
    begin
      frxMemoViewMemo3.Memo.Text := Edit1.Text;
    end;
    
    end.
    
  • gordkgordk St.Catherines On. Canada.
    edited 6:52PM
    since you are working from delphi code you must use the findobject method to find the object before you try to access its properties.
    see the programmers manual on working with report objects
  • edited 6:52PM
    Hi again,

    My suggestion means that you should set the porperty of TfrxMemoView component *in FastScript*.

    In your case, the name of TfrxMemoView is 'Memo3',
    and you are trying to set the value of Delphi side component to the FastReport's component.

    In such case, I would write:

    [In Delphi]
    procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
    begin
      //define and set FastReport variable
      frxReport1.Variables['SomeText'] := '''' + Edit1.Text + '''';
    end;
    

    [In FastReport(PascalScript)]
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    begin
      //refer to FastReport variable
      Memo3.Memo.Text := <SomeText>;
    end;
    

    please do not forget to assign event by using report designer.

    or directly set to Memo3.Memo by using object inspector of report designer.
    (in this case, the value to set is '[SomeText]' because of variable reference.)


    if you don't want to use script,
    procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
    var
      i: Integer;
    begin
      for i := 0 to frxReport1.ComponentCount-1 do begin
        if (frxReport1.Components[i] is TfrxMemoView) and 
           (TfrxMemoView(frxReport1.Components[i]).Name = 'Memo3') then begin
          TfrxMemoView(frxReport1.Components[i]).Memo.Text := Edit1.Text;
          Break;
        end;
      end;
    end;
    
  • gordkgordk St.Catherines On. Canada.
    edited May 2015
    if using the reports onbefore -p0rint event just get the senders hname and cast it to its type to modify it's properties.
    ie
    begin
    if sender.name = 'Memo3' then
    with sender as tfrxmemoview do
    begin
    set any properties here
    sender.memo.text:= 'the text you want';
    end;
    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.