Incrementing value on new page
Hi Guys
D7
RB 15.2
We have the following code in the AfterScroll event of a Query component. It
works well except the variable: TempClaimId is being incremented not only
where it should be (see ****** below) but additionally when a new page in
the report is printed. The unwanted result is that there is a jump in the
calculated value for each new page.....Is this usual behaviour? and if so is
there a way to stop it as we need to variable to increment only where
specifically requested,
Thanks for your help/observation
Glenn
---------------
procedure TCouncilRents.CouncilInfoAfterScroll(DataSet: TDataSet);
begin
try
With IncludedRents do
begin
Close;
Params[0].DataType:=ftInteger;
Params[1].DataType:=ftDate;
Params[2].DataType:=ftDate;
Params[0].Value:=CouncilInfo.FieldByName('UtilCode').AsInteger;
Params[1].Value:=DateTimePicker1.Date;
Params[2].Value:=DateTimePicker2.Date;
open;
end;
ppLabel3.Caption:=IntToStr(IncludedRents.RecordCount)+' transactions have
been located for this period';
If IncludedRents.RecordCount>0 then
begin
//write the temp id to the report and increment
ppLabel10.Caption:='Claim ID: '+IntToStr(TempClaimId);
Inc(TempClaimId); *********
end;
except
on E: Exception do//most likely reason is required labels deleted from
report
begin
MessageDlgCtr('A problem has been encountered generating your
documentation... Please contact Key-Data customer support for advice quoting
the following: ' + E.Message, mtInformation, [mbOk],mrOk, True);
screen.cursor:=crdefault;
end;
end;
----------------------------------------------
D7
RB 15.2
We have the following code in the AfterScroll event of a Query component. It
works well except the variable: TempClaimId is being incremented not only
where it should be (see ****** below) but additionally when a new page in
the report is printed. The unwanted result is that there is a jump in the
calculated value for each new page.....Is this usual behaviour? and if so is
there a way to stop it as we need to variable to increment only where
specifically requested,
Thanks for your help/observation
Glenn
---------------
procedure TCouncilRents.CouncilInfoAfterScroll(DataSet: TDataSet);
begin
try
With IncludedRents do
begin
Close;
Params[0].DataType:=ftInteger;
Params[1].DataType:=ftDate;
Params[2].DataType:=ftDate;
Params[0].Value:=CouncilInfo.FieldByName('UtilCode').AsInteger;
Params[1].Value:=DateTimePicker1.Date;
Params[2].Value:=DateTimePicker2.Date;
open;
end;
ppLabel3.Caption:=IntToStr(IncludedRents.RecordCount)+' transactions have
been located for this period';
If IncludedRents.RecordCount>0 then
begin
//write the temp id to the report and increment
ppLabel10.Caption:='Claim ID: '+IntToStr(TempClaimId);
Inc(TempClaimId); *********
end;
except
on E: Exception do//most likely reason is required labels deleted from
report
begin
MessageDlgCtr('A problem has been encountered generating your
documentation... Please contact Key-Data customer support for advice quoting
the following: ' + E.Message, mtInformation, [mbOk],mrOk, True);
screen.cursor:=crdefault;
end;
end;
----------------------------------------------
This discussion has been closed.
Comments
When making calculations inside a report, it is necessary to use the
TppVariable.OnCalc event only to ensure the calculations is made only
once per traversal. Otherwise there is no guarantee how many times a
given event will fire.
Take a look at the following article on performing calculations inside a
report.
http://www.digital-metaphors.com/RBWiki/Delphi_Code/Calculations/Overview
Note: If you are making numerical calculations (such as the one you have
in your example code) you will need to set the TppVariable VarType
property to a numerical type (ex. Integer).
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com