Font Color Question
Hello,
I need to load a report template at runtime.
Then I need to insure that all fields containing numeric data which are less
than zero appear in red, and otherwise default to black.
What would you suggest as an appropriate way to implement this?
Thank you,
Mike Malinowski
I need to load a report template at runtime.
Then I need to insure that all fields containing numeric data which are less
than zero appear in red, and otherwise default to black.
What would you suggest as an appropriate way to implement this?
Thank you,
Mike Malinowski
This discussion has been closed.
Comments
font color for fields based on the numeric data. The demo report is #12
which shows how to do this.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
I am currently using RB Professional with Delphi 6. I cannot get the RAP
demo to compile. Are there any other demo programs available, or
suggestions you can make as to how I might accomplish setting the font color
of particular objects in a report (ppDBText, ppVariable, etc) based on their
numeric data.
Thank you,
Mike Malinowski
You could create a custom data aware component which does this and use it to
create your reports for the numeric fields coming through the data pipeline.
You can also code a calculation for these components, although the event
handlers will have to be hooked up after you load a template. You would need
to use TppVariable components and code their OnCalc event handler to perform
the check the change the font color and also to grab the value from the data
pipeline and stick it int eh variable's value. This is all easily done in
RAP (which is why I pointed you towards that solution first), where the
template saves the calculations and you don't have to worry about rehooking
them up after the tempalte loads.
unit myDBText;
interface
uses
Classes,
ppCtrls, ppDsgnCT;
type
TmyDBText = class(TppDBText)
protected
function GetTheText: String; override;
end;
implementation
{$R TmyDBText.res}
uses
Graphics,
ppClass;
function TmyDBText.GetTheText: String;
var
ldValue: Double;
begin
Result := inherited GetTheText;
if (CheckForPipelineData) then
begin
ldValue := DataPipeline[DataField];
if (ldValue < 0) then
Font.Color := clRed
else
Font.Color := clBlack;
end;
end;
{***************************************************************************
***
*
** I N I T I A L I Z A T I O N / F I N A L I Z A T I O N
*
{***************************************************************************
***}
initialization
{register the component, the parameters are:
Component Class Name, class name of component
Toolbar Name, name of Toolbar on which component should
appear
Position, position of component on toolbar
HintIndex, (used by the built-in ReportBuilder components)
Loads the Language string
of the specified index as the hint
Hint, Hint text which appears when mouse is
positioned over component on Toolbar
HInstance, Handle of library for this unit, needed to load
bitmap from resource file}
// ppUnRegisterComponent(TppDBText);
ppRegisterComponent(TmyDBText, 'Data Components', 0, 0, 'Colored DBText',
0);
finalization
// ppUnRegisterComponent(TmyDBText);
ppRegisterComponent(TppDBText, 'Data Components', 0, 0, 'Colored DBText',
0);
end.
If you decide to go with event handlers, here is some more information to be
aware of:
--------------------------------------------
Article: Troubleshooting Lost Event Handlers
--------------------------------------------
Let's assume you have created a report in Delphi and assign an event
handlers to the OnPreviewFormCreate event of the report. The event is
generated by Delphi as:
procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);
You then save the report to an RTM file 'Report1.RTM.' The events are
stored as references only, and so the RTM contains:
object ppReport1: TppReport
.
.
OnPreviewFormCreate = ppReport1PreviewFormCreate
end
You then go on to work on a different report. Saving it with under then
name 'Report2.RTM'. Only this time, before you save the report you change
the report component name to: rptOrders. Delphi automatically updates the
event declaration for OnPreviewFormCreate event to:
procedure TForm1.rptOrdersPreviewFormCreate(Sender: TObject);
You then create two buttons on the form, one to load Report1 and preview,
the other to load Report2 and preview. When you run the app and click
Report1, you an error. This is because the Report1.RTM file contains a
reference to ppReport1PreviewFormCreate, a method which no longer exists (at
least with this name) in the form.
One answer is to load all your rtm files into the report component you will
be using for loading. Fix any errors, reassign any events that get cleared.
This will update your rtms to contain the proper event handler names.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
in Delphi which will accomplish this. You could potentially event get away
with one event hadler for all the component by implementing the OnPrint
event which all of the component you are concerned with implement. You can
then assign this event handler to all the appropriate fields. For example:
procedure TForm1.PrintEvent(Sender: TObject);
var
lDataType: TppDataType;
begin
if (Sender is TppDBText) then
begin
lDataType := ppReport1.DataPipeline.CurrentField.DataType;
if (lDataType = dtInteger) or if (lDataType = ftSingle) or (lDataType
= ftDouble) or .... then
begin
if (ppReport1.DataPipeline.CurrentField.Value < 0) then
TppDBText(Sender).Font.Color := clRed
else
TppDBText(Sender).Font.Color := clBlack;
end;
end;
--
Cheers,
Alexander Kramnik
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com