Recent

Author Topic: Adding values in Master Footer  (Read 3808 times)

AKCarlow

  • New Member
  • *
  • Posts: 45
Adding values in Master Footer
« on: November 11, 2014, 08:00:16 pm »
In the Master Footer band of a report I have a rectangle object with this:

Code: [Select]
[[SUM([if([qPrintBills."Charge"]<0,[qPrintBills."Fixed"],[qPrintBills."Charge"]+[qPrintBills."Fixed"])])]+[qPrintBills."Arrears"]+[qPrintBills."Rounding"]]
It produces the result I want when I look at it in the report designer's preview mode, but when I try to view the report at run-time in Lazarus I get an error: invalid variant type class. It crashes at about line 8722 in unit LR_Class, in procedure InternalOnGetValue(ParName: String; var ParValue: String), with the value of ParName '[SUM([if([qPrintBills."Charge"]<0,[qPrintBills."Fixed"],[qPrintBills."Charge"]+[qPrintBills."Fixed"])])]+[qPrintBills."Arrears"]+[qPrintBills."Rounding"]' - ie what is in the rectangle with the outermost [] removed.

If I remove that outer [] in the rectangle object I get no crash at run-time, and in preview and run-time get the same result - three values with + signs between them, rather than their total.

Any suggestions?
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: Adding values in Master Footer
« Reply #1 on: November 12, 2014, 05:41:27 am »
It seems the expression is wrong, it should be: [SUM(Function, DataBandName)+[FIELD]+[FIELD]] although DatabandName could be optional if it is the only masterband.

Applied to your expression it should be:
Code: [Select]
[SUM(if([qPrintBills."Charge"]<0,[qPrintBills."Fixed"],[qPrintBills."Charge"]+[qPrintBills."Fixed"]), databandname)+[qPrintBills."Arrears"]+[qPrintBills."Rounding"]]
or
Code: [Select]
[SUM(if([qPrintBills."Charge"]<0,[qPrintBills."Fixed"],[qPrintBills."Charge"]+[qPrintBills."Fixed"]))+[qPrintBills."Arrears"]+[qPrintBills."Rounding"]]
if you omit the bandname. Functions within expression should not be enclosed in [].

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: Adding values in Master Footer
« Reply #2 on: November 12, 2014, 01:27:47 pm »
Thank you for the reply, Jesusr.

I fixed the [], and it made no difference. I added the bandname, and it made no difference. The error in LR_Class was flagged at statement 'ParValue := FormatValue(CurValue, AFormat, AFormatStr);' so I set the Format back from Number/Custom/€#,##0.00;(€#,##0.00) to Text/None, and it runs without error. Setting the format to Number/1234,5 again produces the error.

As it works in preview but not at runtime, I presume this is a bug. Any suggestions on a work-around?

Talking of bugs, I note that, in designer, if you try to edit a custom format, the format box is empty, even though the value previously set does show in object inspector.

Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: Adding values in Master Footer
« Reply #3 on: November 14, 2014, 12:25:18 am »
It sounds like a locale problem where DecimalSeparator is being set (or not set) by some part of the IDE but is not (or it is) in your program. Please try to isolate the problem in a simple test project and submit a bug report in the bug tracker, don't forget a sample report and information about your locale, I think the output of the locale command in a Terminal window should help to reproduce your problem, but what are you settings in System preferences -> Language & Text (Advanced -> general, numeric separators)

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: Adding values in Master Footer
« Reply #4 on: November 14, 2014, 02:33:49 pm »
Hmmm. I've attached a screenshot of the locale settings, but I would not be sure this is the problem. The numeric separator settings in the project are whatever is their default, as I've not set any. I have a couple of settings for date:
Code: [Select]
ShortDateFormat := 'yyyy/mm/dd';
DateSeparator := '-';
The formatting (€#,##0.00) is working as expected on a memo box with
Code: [Select]
[if([qPrintBills."Charge"]<0,[qPrintBills."Fixed"],[qPrintBills."Charge"]+[qPrintBills."Fixed"])]
in a  MasterData band.

For a workaround, I am doing the desired formatting in a script, which I would paste here except that copy/paste don't work in the script editor, but eg things like
Code: [Select]
...
ToPay := '€' + ToPay + '.00';
...
Memo34.Text := ToPay;
The script also does some other calculations.

Another wee bug ... if you put a script on a memo box, and subsequently delete the script contents and uncheck the script checkbox, it checks it self again as soon as your back is turned.

I'll try to put together a sample project.
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

 

TinyPortal © 2005-2018