Accessing Datatypes of Calc Fields in code
I am writing code that will loop through the objects in a report's bands,
determine if the object is a ppDBText object, obtain the DBText object's
DataPipeline field datatype, and set the format of the field if the datatype
is dtSingle, dtDouble, or dtCurrency. The purpose of this code is to update
report fields that did not have a format set previously to the release of
TXtraDev 2.0 (because of issues with exporting negative numbers). The code,
at least during the testing stages, is set to run in the EUR report's
OnLoadEnd event.
My problem is that I cannot access the datatype of Calculated fields created
in the Query designer, which includes SUM and EXPRESSION calcs which are
used pretty often in my reports. Here is a sample of the code that I am
using to accomplish my goal:
procedure TfrmRptEndUserReporting.FormatCurrFields(var aRpt: TppReport);
var
i,j,k: integer;
lsFieldName: String;
lDataType: TppDataType;
begin
with aRpt do
begin
for i := 0 to BandCount - 1 do
begin
for j := 0 to Bands[i].ObjectCount - 1 do
begin
if Bands[i].Objects[j] is TppDBText then
begin
lsFieldName := TppDBText(Bands[i].Objects[j]).DataField;
lDataType :=
Bands[i].Objects[j].DataPipeline.FieldObjects[lsFieldName].DataType;
if lDataType in [dtSingle,dtDouble,dtCurrency] then
TppDBText(Bands[i].Objects[j]).DisplayFormat :=
'$#,0.00;($#,0.00)';
end;
end;
end;
end;
end;
The procedure is included in the EUR report's OnLoadEnd event, and works
fine on non-calced fields. When I look at the dataview on the Calc tab of
the EUR report, the datatype shows up for Calced fields in a similar manner
as for non-calced fields.
Thanks in advance.
determine if the object is a ppDBText object, obtain the DBText object's
DataPipeline field datatype, and set the format of the field if the datatype
is dtSingle, dtDouble, or dtCurrency. The purpose of this code is to update
report fields that did not have a format set previously to the release of
TXtraDev 2.0 (because of issues with exporting negative numbers). The code,
at least during the testing stages, is set to run in the EUR report's
OnLoadEnd event.
My problem is that I cannot access the datatype of Calculated fields created
in the Query designer, which includes SUM and EXPRESSION calcs which are
used pretty often in my reports. Here is a sample of the code that I am
using to accomplish my goal:
procedure TfrmRptEndUserReporting.FormatCurrFields(var aRpt: TppReport);
var
i,j,k: integer;
lsFieldName: String;
lDataType: TppDataType;
begin
with aRpt do
begin
for i := 0 to BandCount - 1 do
begin
for j := 0 to Bands[i].ObjectCount - 1 do
begin
if Bands[i].Objects[j] is TppDBText then
begin
lsFieldName := TppDBText(Bands[i].Objects[j]).DataField;
lDataType :=
Bands[i].Objects[j].DataPipeline.FieldObjects[lsFieldName].DataType;
if lDataType in [dtSingle,dtDouble,dtCurrency] then
TppDBText(Bands[i].Objects[j]).DisplayFormat :=
'$#,0.00;($#,0.00)';
end;
end;
end;
end;
end;
The procedure is included in the EUR report's OnLoadEnd event, and works
fine on non-calced fields. When I look at the dataview on the Calc tab of
the EUR report, the datatype shows up for Calced fields in a similar manner
as for non-calced fields.
Thanks in advance.
This discussion has been closed.
Comments
newsgroup thread (general), dated 4/19/02:
Obtaining attributes of report objects
I have been having problems with my newsgroup reader, and did not see the
response to the previous other post. Apologies for redundancy.
P.S. Thanks to A.K.. It worked like a charm.