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

Comparing Fields from 2 different Subreports in a TppVariable created at RunTime

edited May 2002 in General
This is kind of a tricky problem...

I've got a report that has two subreports sitting side by side. In each
subreport the same fields are created at runtime. (The idea behind the
report is to compare two different records that have the same fields)The two
pipelines are pointing to AstaClientDataSets - one of which is filtered.

So this is how it looks:

GROUP: AAA AAA
NUMBER: 123 123

etcetera

After much mucking around everything is going (seemingly fine).

However now I want to compare the fields at runtime and have a TppVariable
which displays a variable if any of the fields are different. ie:

GROUP: AAA AAA
NUMBER: 123 124 DIFFERENT
<-This is the TppVariable

SO here's what I did: when I created the Fields I also created a TppVariable
and assign the OnPrint procedure to one I've already created:

procedure TForm1.ppVariablePrint(Sender: TObject);
var
CurrentLabelIndex: integer;
VariableName: string;
Changed: boolean;
FieldName: string;
begin
VariableName := TppVariable(Sender).Name;
try
CurrentLabelIndex := StrToInt(Copy(VariableName,
11,Length(VariableName) - 10)); // This gets the current field number
except
CurrentLabelIndex := -1;
end;
if CurrentLabelIndex = -1 then
Exit;
FieldName := DBFields[CurrentLabelIndex].DataField; // DBFields is an
array of TppDBText which holds the first value (ie AAA or 123)
Changed := ppDBPipeline1.GetFieldForName(FieldName).AsString <> {Left row}
ppDBPipeline2.GetFieldForName(FieldName).AsString;
{Right row}
if Changed then
TppVariable(Sender).Value := 'DIFFERENT'
else
TppVariable(Sender).Value := '';
end;

Now this seems to work perfectly for the first few records. But then it
starts to go haywire and reporting fields that don't have any changes as
"DIFFERENT".

I've tried:
using OnCalc instead
Reseting TppVariable after traversal, after report

Help me Obi Wan Kenobis - you're my only hope!

Comments

  • edited May 2002
    In the right most subreport, create a variable component in its detail band
    and code its OnCalc event handler to compare the current pipeline values. I
    created a test report and it works fine.

    procedure TForm1.ppVariable1Calc(Sender: TObject; var Value: Variant);
    begin

    if Orders['CustNo'] = Customer['Custno'] then
    Value := 'True'
    else
    Value := 'False';

    end;


    Cheers,

    Jim Bennett
    Digital Metaphors

This discussion has been closed.