Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: Can I use a variable from a user dialog in a dataset definition  (Read 8764 times)

ham13

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #15 on: November 28, 2022, 11:07:00 pm »
Thank you for your help! I understand now that I can use JS in LPD scripts. How ever I cannot find a reference to the function reopenDatasource("Data") in either language. That's why I requested a source for the codeing used in LRD.

This code, when I add it to my project and use the proper variable, the program stops working.

txtYear is the line edit in my dialog. Year is the variable containing the data (Year).
Databand6 is the datband on the report page. I have defined the variable Year just aas you defined id.

Dialog.txtYear.text=getVariable("Year");
Dialog.exec()==1;

function beforeDataPrint()
  {
  setVariable("Year", Dialog.txtYear.text);
  }

Reportpage1_DataBand6.preparedForRender.connect(beforeDataPrint);


This code, that I came to use after many tries, works.  I do not know why but it does work.

Dialog.exec() == 1

var Year = Dialog.txtYear.text
var Date = Dialog.txtDate.text
var Check = ""

beforeDataPrint();

function beforeDataPrint() {
Check = "Function";
setVariable("Year", Dialog.txtYear.text);
reopenDatasource("tblneighborhood");
}

Thanks

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #16 on: November 29, 2022, 11:16:03 am »
I think you set the datasource for your DataBand6
It's affect to the program crash

I can't find the cause yet

ham13

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #17 on: November 29, 2022, 05:25:17 pm »
Yes, that is the name of the band shown on the report page when I click on the data band. It shows DataBand6 in yellow. The datasource for the band is set to tblneighborhood. I'll set it to DataBand1 and see what happens.

Thanks

ham13

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #18 on: November 29, 2022, 05:32:06 pm »
Setting Reportpage1_DataBand6.preparedForRender.connect(beforeDataPrint) to Reportpage1_DataBand1.preparedForRender.connect(beforeDataPrint) produces error "line 9 reference Reportpage1_DataBand1.preparedForRender.connect(beforeDataPrint)is not defined"

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #19 on: November 29, 2022, 06:42:04 pm »
Reportpage1_DataBand6 - you have thi band
Reportpage1_DataBand1 - and don't have this

Reportpage1_DataBand6 means PageName_BandName

ham13

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #20 on: December 01, 2022, 05:40:54 pm »
I'm not sure what you mean from your message. I know that the code should be "Reportpage1_DataBand6" because it is defined in the report and "Reportpage1_DataBand1" is not. That is why I used that reference in the code when I tested it. Hopefully you will find the cause of the crash.

Regards
Marty

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #21 on: December 01, 2022, 06:56:55 pm »
I've asked Alex about crash.
We've discussed about and this behavior of band (crash in such case) it's right, normal.
I can quote our talk. but it's in Russian and I'm too lazy to translate it :) Sorry  ;)

ham13

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #22 on: December 02, 2022, 05:20:20 pm »
OK. So, unless I specify Reportpage1_DataBand1 in the code it will crash and this is normal behavior. That does not sound right. Well that leaves only one option; I'll use the code that works. I had hoped for a better solution. Let me know if I have misunderstood your comments.

Again thanks for your patience and efforts to resolve this problem. :)

Regards,

Marty

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #23 on: December 02, 2022, 09:59:39 pm »
Well!
Good luck :)

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Can I use a variable from a user dialog in a dataset definition
« Reply #24 on: December 05, 2022, 03:55:55 pm »
ham13,
Quote
OK. So, unless I specify Reportpage1_DataBand1 in the code it will crash and this is normal behavior. That does not sound right
if we write somethig like this:
Code: [Select]
    QObject* object = new QObject();
    delete object;
    qDebug() << object->objectName();
Will application crash be the normal behavior?
In your case something like this happens.
If you change on preparedForRender slot the variable linked with rendering datasource
this will invalidate datasource in rendering cycle.
Possible I have to make some additional checks for this case, but the behavior is normal :)
« Last Edit: December 05, 2022, 03:58:36 pm by Arin Alex »