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

Variables howto

edited February 2002 in General

Hi,

I really don't understand how the resettype/resetcomponent works :

I have a 3 level report (master detail subdetail) : master is for musicians, detail is for the songs they wrote,
subdetail is for what the rights they earned for every song.

Since I use subreports, I have to use variables (and not DBcalc)

- main has a variable (variable1) in its group footer to calculate the total earned by every musician,
- subreport 1 has a variable (variable2) to sum what is earned for each song but I want several sums depending
on the type of rights (more on this later)
- subreport 2 has a variable (variable3) in its summary band to do the same thing (total depending on type of
rights), just to check the values are correct.

Also, since the report is ordered by rights type, I have a group in subreport 2 with a dbcalc that gets (once more)
this total by type of rights.

My problem is that the values I get are different. The (automatic) DBcalc seems to always give the good result but
not the variables. All three have this in OnCalc :

procedure TFImprimeDecomptes.vTotDuOeuCalc(Sender: TObject; var Value: Variant);
begin
if kbmtype.Value='DEP' then Begin
Value:=Value+kbmDu.Value;
End;
end;

Variable2 is placed in the song group footer with a resettype of "groupend" (btw what's the difference between
groupstart and groupend ? they give the same results), reset component on this group, calctype of
DataPipelineTraversal and Calccomponent on the subdetail's pipeline (kbm).

What happens is that when there are 'DEP'-type rights that span on two or more pages, the first line of the
second page is added twice to the variable. What did I do wrong ?

Delphi 6.01 / RB 6.03

Thanks !

Comments

  • edited February 2002
    The reset values are also settable by the timing dialog (right-click over
    the variable in the designer).

    Set the traversal type to on Traversal and not on DataPipelineTraversal.
    This is the problem. The DataPipelineTraversal fires more often than the on
    Traversal. Traversal is guranteed to fire only when moving forward one
    record in the dataset. DataPipelineTraversal fires whenever the record
    position moves forwards or backwards (the report engine moves forwards, then
    backwards, when the group breaks).


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited February 2002
    > Set the traversal type to on Traversal and not on DataPipelineTraversal.

    No, it doesn' solve anything. Already tried that.


    ..or to be more precise, on the current (sub)report's pipeline which is no use to me (the OnCalc event is fired only
    for the first record of course). I want to find a way of adding some result from one subreport to it's parent. Is this at
    all possible ? There must be a howto somewhere but could not find it (also tried the tech-tips forum).

    * not with DBcalcs
    * not with variables (or get my useless behaviour)

    I can imagine... create a variable on the subreport that contains the subdetail data i'm interested in (with traversal
    of course because there it works), hide this variable and in its OnCalc event update the parent's report variable
    value. Is that the only way ? And will it work as I expect it to ?

    Why don't you create either :
    - a special OnDataPipelineTraversalFireOnce event (what's the use of the OnDataPipelineTraversal ?)
    - a DBcalc that can work across subreports

    One last thing : what's the difference between the resettypes GroupEnd and GroupStart ?

    Thanks in advance.
  • edited February 2002
    You're right, DBCalcs don't work over subreports in the main report. You
    can use a variable in the detail band ov the subreport to increment the
    value of a variable in the main report summary band.

    procedure TForm1.vblDetailValueCalc(Sender: TObject; var Value: Variant);
    begin
    {display the total in the summary band}
    vblSummaryTotal.Value := vblSummaryTotal.Value + 1;

    {display the new total}
    Value := vblSummaryTotal.Value;
    end;


    Cheers,

    Jim Bennett
    Digital Metaphors

This discussion has been closed.