FastReport VCL Standard Dataset problem

Hello,

The situation is the following:

We have an existing report made using FastReport VCL Standard. The report is dynamic and created purely with code i.e. there is no .fr3 file to view or edit. For some reason the report has started to cause Access Violation errors and we have found out that the source of the error is frxEngine and since we do not have the source code for that we cannot see the root cause.

We are now coming to conclusion that we should build the report layout using the report designer and create a dedicated .fr3 file for it. The data for the report is composed by a quite complex Sql query and then stored in a temporary dataset called mdReportData (TdxMemData) in a process that is run before creating the report. I am new to FastReports and a bit lost on how to proceed from here. I created a corresponding dsReportData (TfrxDBDataset), selected it as the datasource in the report designer and can select and drop the data fields into the report. However, when I run the report there is no data. dsReportData.DataSet.Active is set to TRUE. Should I use some other dataset component?

What is it that I am missing? Could you provide some sample code of a similar case. Do I have to code events for the dsReportData dataset, like OnCheckEOF, OnFirst, OnNext etc. or should they be created automagically?

This is a critical bug for us and should be resolved urgently. Therefore I would appreciate your help and assistance in finding a solution to it.

Comments

  • PolomintPolomint Australia

    G'day,

    Would it be possible to post a "redacted" version of your Report Code here, so those of us with access to Source 😉 can check out why it is failing. Not sure if that is easy to do, but you might gain some insight yourself / yourselves...

    Cheers, Paul

  • Good day,

    Thank you for your message. As I said, I am an absolute beginner with FastReport, but not to new to creating reports.

    I got progress with creating a frxUserDataset and defining needed events for traversing the data. Now I need to study how to format fields, headers, footers, sub-totals, totals etc. properly.

    Cheers,

    Markku

  • PolomintPolomint Australia

    G'day Markku,

    This is all reasonably easy to do.

    In the suite of Reports in our biggest Project we use a mixture of Delphi code and "basic template stuff" from an .fr3 File (stored in the *.dfm File). But a lot of the "smarts" are in the code.

    You need to look at the "Before Print" Events for your Report as a whole, and for each Band, You will also need to have some "setting up" code to make sure that each of the Fields in your Report has an associated Delphi variable. Values like "running totals" need care because if your Report is multi-pass, you only want to calculate the values in one of the passes (we do it on the "Final Pass"). Formatting can be done a couple of ways: by setting the Field's "format" Properties; or just using Delphi to create a Text string and assigning that to the Field Variable.

    Experiment with a simple case first and you'll work out what suits your needs.

    Cheers, Paul

  • Hello,

    I have played a bit with FR and there has been some progress. I have been able to create the basic structure for the report, but I do not seem to get such a simple thing as Group Total working out-of-the-box. Simplified, the setup is following:

    DataSet:

    dsReportData: TfrxUserDataset

    Populated with Delphi procedure.


    DataItems:

    PlanCD, ProductCD, Amount

    Containing data like this:

    A12345, S123, 123

    A12345, S345, 456

    A32469, S435, 345

    A33456, S567, 987

    A33456, S789, 126

    etc.

    Page1:

    1. GroupHeader, grouped by dsReportData.PlanCD (Showing the PlanCD value)
    2. MasterData band with dsReportData.ProductCD and dsReportData.Amount
    3. GroupFooter with Memo text Sum(dsReportData.Amount, MasterData) (The pain-point)

    Doublepass is on.

    The problem:

    The GroupFooter sum works only if there is only one ProductCD and Amount value respectively. If there are, for example, 2 ProductCDs and Amount values with the same PlanCD value, the Amount values are shown separately after each other in the SUM Memo. How is this even possible? I have followed the documentation and the formula should be correct.

    I have to say that I am astonished that achieving such a basic thing as summing values seems to require a lot of effort with FR.

    I would be most grateful to find out how to sum Amount values with the same PlanCD value.

    Cheers,

    Markku

  • MtkMtk
    edited May 31

    Hello,

    I have studied this a bit more and function COUNT gives correct number for Amount values, but AVG gives an error message saying

    "Could not convert variant of type (String) into type (Double)"

    So, this seems to be a problem with type conversions.

    Could you suggest a trick how to calculate the SUM of the Amount values?

  • This is becoming even weirder. There are other numeric fields in the dataset and they can be summed just fine, but not this one field! I had to create a variable converting Amount from string to float, then figure out a formula to sum that variable. Easy living....

  • PolomintPolomint Australia

    G'day Markku,

    You'll will appreciate that it is very difficult to help without seeing more of your design! 😉

    Can you give any information on the declaration of the Data Fields? Are the Exceptions related to the original Data Elements, or intermediate Variables? I am struggling to picture how the elements you describe above hang together...

    What would really help us "remote users" is if you could reduce your problem to a test program and post it here.

    As you say "achieving such a basic thing as summing values" is quite straightforward in most cases. Our main Application has 40+ Reports and many of these have quite complex Grouping and Totalling setups. In a lot of cases we are able to use logic built into the Report's Design. We don't need to fall back to Delphi code in every case.

    For the most part FastReport handles things quite simply. But sometimes we have to get creative where Database Design or Business Rules get in the way!

    Cheers, Paul

  • Hi Paul,

    Thank you for your contribution. I got the summing up finally sorted out. I know it is very frustrating trying to help without seeing any code, but I am sorry, but the company is very strict when it comes to showing any source code. I hope you understand.

    One more thing: Do you happen to know easy/practical ways to localize a report i.e. changing the header and other static texts based on language used on the fly. Or should I create a new discussion for this question...

    Cheers,

    Markku

  • PolomintPolomint Australia

    G'day again Markku,

    Thanks for the update. Glad you have made progress.

    On you supplementary question...

    We do exactly what (I think) you want with code in the BeginDoc and BandBeforePrint Events.

    You need to have declare named "Memos" in the designed document, then link these t

  • PolomintPolomint Australia

    [ooops! Phone ran out of battery, I didn't think my last post went out! And I hadn't fixed the typos!!]

    Part II

    You need to have declared named TfrxMemoView Objects in the designed document, then linked these to Global Variables in the Form containing your Report. As with most of the features of Delphi / FastReport there are a couple of ways to do this.

    You can then set values on the Variable's Text Property to suit.

    We use this method to "tweak" the Report Header and Page Footer Bands to show such things as:

    • user-selected filtering and / or sorting of Dataset(s) used in the Report
    • whether report was run in "production" or "debug" mode
    • version of the App (and also FastReport itself) used to Preview / Print the Report

    The Headers and Footers don't need to be driven directly from the content of your Database(s),

    Cheers, Paul

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.