How to overwrite TppDBText value?
Hi,
I'm trying to indicate to the user that a negative value in any column of
the report is invalid by overwriting the Text property of the TppDBText
component, Unfortunately it doesn't seem to work, the original database
value is always printed. This is the code:
procedure TMyReport.DetailBandBeforePrint(sender : TObject);
var
i : integer;
fieldname : string;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TppDBText then
begin
fieldName := TppDBText(Components[i]).DataField;
if cdsdata.fieldByName(Fieldname).AsInteger < 0 then
TppDBText(Components[i]).SetText('Invalid');
end;
end;
end;
Any assistance would be much appreciated.
Susie
I'm trying to indicate to the user that a negative value in any column of
the report is invalid by overwriting the Text property of the TppDBText
component, Unfortunately it doesn't seem to work, the original database
value is always printed. This is the code:
procedure TMyReport.DetailBandBeforePrint(sender : TObject);
var
i : integer;
fieldname : string;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TppDBText then
begin
fieldName := TppDBText(Components[i]).DataField;
if cdsdata.fieldByName(Fieldname).AsInteger < 0 then
TppDBText(Components[i]).SetText('Invalid');
end;
end;
end;
Any assistance would be much appreciated.
Susie
This discussion has been closed.
Comments
Instead of altering the actual text of the TppDBText component, try placing
a TppLabel over the DBText with its Visibility set to False. Then toggle
the visibility of each component as you need.
if cdsdata.fieldByName(Fieldname).AsInteger < 0 then
begin
TppDBText(Components[i]).Visible := False;
Label.Visible := True;
end
else
begin
TppDBText(Components[i]).Visible := True;
Label.Visible := False;
end;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Interesting suggestion. I have a variable number of TppDBText's so it won't
be the easiest thing to implement.
In the wee small hours of this morning, I came up with this solution.
Assign the following event handler to the OnGetTextEvent of each of my
TppDBText's
procedure TdmSingleReport.DoDBGetText(Sender: TObject; var Text: String);
var
Value : double;
fieldName : string;
begin
if Sender is TppDBText then
begin
fieldName := TppDBText(Sender).DataField;
Value := cdsdata.fieldByname(Fieldname).AsFloat;
if Value = BAD_DATA then
Text := 'Bad';
end;
end;
end;
It seems to work but please let me know if I've missed something.
Thanks for your assistance
Susie
Sorry, I was not aware you were using multiple DBTexts... your solution
seems to be much better for your situation. The only issue I can see you
may run into is that the GetText event for a DBText will fire more than once
per detail band print. This could cause issues down the road as you create
a larger report, or perhaps in a completely different report. One solution
would be to use TppVariables instead of TppDBTexts. Then you could use the
OnCalc event of the TppVariable component to pull the data directly off your
datapipeline, make calculations on it, and display it how you want. The
OnCalc event of the TppVariable is guarenteed to only fire once per detail
band print.
But... if this works for you, I would stick with it. No need to re-program.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for your advice, I see what you mean. I shall leave as is for the
moment but follow your advice if there are any later problems.
Thanks again
Susie