Search Results for

    Show / Hide Table of Contents

    Interactive reports

    In interactive reports, one can define a reaction for mouse-click on any of the report objects in a preview window. For example, a user can click on the data line, and thus run a new report with detailed data of the selected line.

    Any report can become interactive. To perform this, you only need to create a TfrxReport.OnClickObject event handler. Here is a code example of this handler below:

    Pascal:

    procedure TForm1.frxReport1ClickObject(Page: TfrxPage; View: TfrxView;
      Button: TMouseButton; Shift: TShiftState; var Modified: Boolean);
    begin
      if View.Name = 'Memo1' then
        ShowMessage('Memo1 contents:' + #13#10 + TfrxMemoView(View).Text);
      if View.Name = 'Memo2' then
      begin
        TfrxMemoView(View).Text := InputBox('Edit', 'Edit Memo2 text:', TfrxMemoView(View).Text);
        Modified := True;
      end;
    end;
    

    C++:

    void __fastcall TForm1::frxReport1ClickObject(TfrxView *Sender,
          TMouseButton Button, TShiftState Shift, bool &Modified)
    {
      TfrxMemoView * Memo;
      if(Memo =  dynamic_cast <TfrxMemoView *> (Sender))
      {
        if(Memo->Name == "Memo1")
          ShowMessage("Memo1 contents:\n\r" + Memo->Text);
        if(Memo->Name == "Memo2")
        {
          Memo->Text = InputBox("Edit", "Edit Memo2 text:", Memo->Text);
           Modified = true;
        }
      }
    }
    

    In the OnClickObject handler, you can do the following:

    • modify contents of an object or a page, passed to the handler (thus, the «Modified» flag should be specified, so that the modifications would be taken into consideration);

    • call the TfrxReport.PrepareReport method for reconstructing/rebuilding a report.

    In this example, clicking on the object with the «Memo1» name results in displaying a message with the contents of this object. When clicking on the «Memo2,» a dialogue is displayed, where the contents of this object can be modified. Setting of the «Modified» flag to «True» allows holding and displaying alterations.

    In the same way, a different reaction for a click can be defined; it may, for example, run a new report. It is necessary to NOTE the following. One TfrxReport component can display only one report in the preview window. That is why one should run a report either in a separate TfrxReport object, or in the same one, but the current report must be erased.

    To give a prompting indication about clickable objects to the end user, we can modify the mouse cursor when it passes over a clickable object in the preview window. To do this, select the desired object in the report designer and set it’s cursor property to something other than crDefault.

    One more detail concerns the defining clickable objects. In simple reports, this can be defined either in the object’s name, or in its contents. However, this cannot always be performed in more complicated cases. For example, a detailed report should be created in a selected data line. A user clicked on the «Memo1» object with the '12' contents. What data line does this object refer to? That is why you should know the primary key, which identifies this line unambiguously. FastReport enables to assign a string, containing any data (in our case the data of the primary key), to every report’s object. This string is stored in the TagStr property.

    Let us illustrate this process by an example of a report, which is included in the FastReportDemo.exe - 'Simple list' demo. This is the list of clients of a company, containing such data as «client’s name,» «address,» «contact person,» etc. The data source is the «Customer.db» table from the DBDEMOS demo database. This table has a primary key, i.e. the «CustNo» field, which is not presented in the report. Our task is to determine what record it refers to by clicking on any object from the finished report, which means to get the value of the primary key. To perform this, it is sufficient to enter the following value into the TagStr property of all the objects, lying on the Master Data band:

    [Customers."CustNo"]
    

    During a report’s building, the TagStr property’s contents are calculated in the same way, as contents of text objects are calculated; this means that the variables’ values are substituted in place of all variables. A variable in this particular case is what is enclosed into the square brackets. That is why the lines of the '1005', '2112', etc. types will be contained in the TagStr property of the objects lying on the Master Data after report building. A simple conversion from a string into an integer will give us a value of the primary key, with which a required record can be found.

    If the primary key is composite (i.e. it contains several fields) the TagStr property’s contents can be the following:

    [Table1."Field1"];[Table1."Field2"]
    

    After constructing a report, the TagStr property contains values of the '1000;1' type, from which it is rather not difficult to get values of a key as well.

    Back to top © Copyright Fast Reports Inc.