Recent

Author Topic: LazReport, User functions problem  (Read 4402 times)

derles

  • New Member
  • *
  • Posts: 35
LazReport, User functions problem
« on: January 14, 2014, 09:59:26 pm »
Hello.

I have created an UserFunction and I assigned it to the OnUserFunction Event:

Code: [Select]
procedure TfrmRepProduccionHilanderia.frReport1UserFunction(const AName: String; p1, p2, p3: Variant; var Val: Variant);
var
   cPorcent: real;
begin
   if AName = 'MYFUNCTION' then
   begin
      cPorcent := frParser.Calc(P1);
      Val := FormatFloat('0.00',cPorcent)+'%';
   end;
end;

This is a simple function to ilustrate my problem.

In the report I invoke this functiojn in a memo object in this way:

[MYFUNCTION(dbQuery."cPorcent")]

In this case it works OK: on cPorcent = 5.7, I get "5.70%", no problem there.

The problem is in a GroupFooter band, where I need to invoke my function like this:

[MYFUNCTION(SUM(dbQuery."cPorcent",MasterData1))]

in this case, using a SUM() function as parameter,  frParser.Calc(P1) always returns 0.
Why is that? The user defined function only accept db fields? I hope not !

Tks !

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: LazReport, User functions problem
« Reply #1 on: February 15, 2014, 10:09:11 pm »
I have similar problem with User defined function and OnUserFunction event handler.

When I use [MYFUNCTION(...)] event handler is called,
but when I use [sum(MYFUNCTION(...))] event handler is not called also is not called when I define variable in LazReport and assign to Expression MYFUNCTION(...)

Is it as expected ? or is it incomplete implementation of user functions ?

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: LazReport, User functions problem
« Reply #2 on: March 01, 2014, 07:40:24 pm »
Afaik from FR 2.5
[MYFUNCTION([SomeQuery."Field"])] is correct ,so
[MYFUNCTION(SUM([SomeQuery."Field"]))]  should work too (note brackets around query).

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: LazReport, User functions problem
« Reply #3 on: March 03, 2014, 12:48:56 pm »
  [MYFUNCTION([SomeQuery."Field"])] is correct ,so
Yes

  [MYFUNCTION(SUM([SomeQuery."Field"]))]  should work too (note brackets around query).
may be, but I wrote about:

  [sum(MYFUNCTION([SomeQuery."Field"]))]
so UserFunction is nested into standard function

I have reported it as bug: http://bugs.freepascal.org/view.php?id=25803
« Last Edit: March 03, 2014, 01:19:07 pm by LacaK »

 

TinyPortal © 2005-2018