Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

wrong data fetched

Hello,
I have a very strange problem, which appears in a complex situation, but I try to strip it down to the essence as much as I can (my English is not so good...)

In short this is what happends.
Datamodule DM has a procedure :

procedure print( var myTekst: string )

In that procedure the following code is executed:
- the local, private variable TekstToPrint is assigned 'myTeskt' ==> TekstToPrint := myTekst
- report is created, (it is a variable inside this procedure)
- the Layout is loaded from the database.
- The report.print is called.

The report uses a TppJITPipeline.
In the onGetFiledValue the result is the value of the local variable "TekstToPrint"

This all takes place in a Form that is dymamicly created, and the datamodule is declared private, and is created in the onCreate of the form.

So far so good.

NOW: The second, third, fourth..forms that calls this procedure print all the value of the FIRST form (!)

For example: When the procedure starts, myTekst="Clientnumber Two", the local variable is "Clientnumber Two",
But the OnGetValue has result "Clientnumber ONE".

This only happens if I use a dynamicly created reportcomponent and load the layout form the database.

I hope somebody van shed some light on this! I spend many days on this..

thank you very much,

kind regards,

Dirk Janssens.

Comments

  • Hi Dirk,

    This sounds like a naming/referencing issue.

    Try tracing into the code that assigns the TekstToPrint variable and see if the value is correct. My guess is that the wrong form is being referenced when accessing that variable inside the OnGetFieldValue event.

    It may also be helpful to trace into the OnGetFieldValue for each JITPipeline to be sure the correct event is firing for each form/datamodule.
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi Nico,

    Thank you for your quick response.

    If I put a breakepoint in the procedure, alle the variables have the right values. But after the call "report.print", I jump to the breakpoint of the JIT-pipeline, and all of the sudden the local variables have the wrong values (!).
    If I use a reportcomponent on the Datamodule everything is OK.
    (As if 'loading the tepmlate causes the report to execute the getFieldValue-event in another instance of the datamodule....)
  • I ""solved" the problem, but I am confused...
    This is what happends:

    Directly after creating the datamodule, I give it another (random) name, and then the problem is solved.

    But, If i do not give it another name, Delphi does that for me. A showmessage(self.name) gives:
    DM, DM_1, DM_2, DM_3 etc...
    Using the automatic generated name gives problemes.

    Using code like

    DM.name := 'myNAme'+random(1000).tostring

    solved the problem (!)

    What is happening ??
  • Hi Dirk,

    I'm not completely sure why the above works however it may have something to do with the timing at which you are changing the name of the data module.

    Note that when loading a template, all the event and pipeline references are saved with that template when it is saved. This means that if you are loading a template that needs to access a different pipeline or event that was assigned for the original, you will need to re-assign them after it is loaded.

    It's possible that if you are changing the data module name after the template is loaded, the references are automatically resolved.
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • To fully resolve this, I would recommend utilizing report parameters.

    This approach eliminates the need for using a Pipeline or similar methods; instead, you can directly assign the report parameter to the dynamically created report and use it in your report template.
    Yusuf Zorlu
    MicrotronX - Speditionssoftware vom Profi
    https://www.microtronx.com
Sign In or Register to comment.