Problems Populating Generic Report
Hello:
I wrote a generic report to produce code listings for my applications.
The report has a data pipeline which points to the data records for
the selected code table. I have already defined appropriate header
and summary fields and simply need to populate the report with the
field labels and dbFields. I call a procedure called ProcessFields
and it populates the report. The procedure is listed at the end of
this message. This works great but I have two problems that I need
help on.
1) Data for fields of char type appear on the report but data for
fields of numeric type do not appear on the report. I don't know
about other data types.
What do I need to do to get my numeric fields to print?
2) I need to calculate the width of the fields. I am using
FieldWidth := Fields[I].Size*7; because I couldn't get the correct
size using your ppGetSpTextWidth function. Here is one of my attempts
to use it which failed:
FieldWidth := Fields[I].Size*ppGetSpTextWidth(Font,Caption);
What should I use to calculate the field width?
--------------
I don't want to have to go through the lComponent and other procedures
used in the Report Wizard if I don't have to.
Thanks,
Sidney
-------------- ProcessFields ---------------
procedure TrptCodeListing.ProcessFields;
var
I,LabelWidth,FieldWidth,FieldLeft: Integer;
begin
FieldLeft := 0;
with plSelectedCode.DataSource.DataSet do
begin
SetLength(ppLabels,FieldCount);
SetLength(ppFields,FieldCount);
for I := 0 to Fields.Count-1 do
begin
// --- Create Label for field
ppLabels[I] := TppLabel.Create(Self);
with ppLabels[I] do
begin
Band := isReport1.HeaderBand;
Caption := Fields[I].DisplayLabel;
spTop := 50;
spLeft := FieldLeft;
LabelWidth := ppGetSpTextWidth(Font,Caption)+10;
Font.Style := Font.Style+[fsBold,fsUnderline];
end;
// --- Create DBText for field
ppFields[I] := TppDBText.Create(Self);
with ppFields[I] do
begin
Band := isReport1.DetailBand;
spTop := 0;
spLeft := FieldLeft;
DataPipeline := plSelectedCode;
DataField := Fields[I].FieldName;
FieldWidth := Fields[I].Size*7;
spWidth := FieldWidth;
end;
// --- Determine offset for next field
FieldLeft := FieldLeft+Max(LabelWidth,FieldWidth)+10;
end;
end;
I wrote a generic report to produce code listings for my applications.
The report has a data pipeline which points to the data records for
the selected code table. I have already defined appropriate header
and summary fields and simply need to populate the report with the
field labels and dbFields. I call a procedure called ProcessFields
and it populates the report. The procedure is listed at the end of
this message. This works great but I have two problems that I need
help on.
1) Data for fields of char type appear on the report but data for
fields of numeric type do not appear on the report. I don't know
about other data types.
What do I need to do to get my numeric fields to print?
2) I need to calculate the width of the fields. I am using
FieldWidth := Fields[I].Size*7; because I couldn't get the correct
size using your ppGetSpTextWidth function. Here is one of my attempts
to use it which failed:
FieldWidth := Fields[I].Size*ppGetSpTextWidth(Font,Caption);
What should I use to calculate the field width?
--------------
I don't want to have to go through the lComponent and other procedures
used in the Report Wizard if I don't have to.
Thanks,
Sidney
-------------- ProcessFields ---------------
procedure TrptCodeListing.ProcessFields;
var
I,LabelWidth,FieldWidth,FieldLeft: Integer;
begin
FieldLeft := 0;
with plSelectedCode.DataSource.DataSet do
begin
SetLength(ppLabels,FieldCount);
SetLength(ppFields,FieldCount);
for I := 0 to Fields.Count-1 do
begin
// --- Create Label for field
ppLabels[I] := TppLabel.Create(Self);
with ppLabels[I] do
begin
Band := isReport1.HeaderBand;
Caption := Fields[I].DisplayLabel;
spTop := 50;
spLeft := FieldLeft;
LabelWidth := ppGetSpTextWidth(Font,Caption)+10;
Font.Style := Font.Style+[fsBold,fsUnderline];
end;
// --- Create DBText for field
ppFields[I] := TppDBText.Create(Self);
with ppFields[I] do
begin
Band := isReport1.DetailBand;
spTop := 0;
spLeft := FieldLeft;
DataPipeline := plSelectedCode;
DataField := Fields[I].FieldName;
FieldWidth := Fields[I].Size*7;
spWidth := FieldWidth;
end;
// --- Determine offset for next field
FieldLeft := FieldLeft+Max(LabelWidth,FieldWidth)+10;
end;
end;
This discussion has been closed.
Comments
blank? Or are they never actually encountered when traversing Fields in your
loop? This might have something to do with the calculation of the FieldWidth
(i.e. components are overwriting each other.)
ppGetSpTextWidth(Font,Caption) will give you the width of the string
'Caption' on the canvas in screen pixels.
Fields[I].Size*ppGetSpTextWidth(Font,Caption) is a meaningless value. Size
is simply the size of the database field in bytes so the result is the
number of bytes times the width of the caption of the component in screen
pixels. Also, Caption is not the name of the field. Caption is the text that
appears in the designer, not what prints in the report. To measure the
actual width of the field you need to do something like this:
ppGetSpTextWidth(ppFields[I].Font,
plSelectedCode.DataSource.DataSet.Fields[I].FieldName) ;
--
Cheers,
Alexander Kramnik
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
Thanks for your help. You helped me realize what the ppGetSpTextWidth
function was doing. The reason numeric fields were not displaying is
that their Fields[I].Size is zero. Using Fields[I].FieldName only
makes the fields as wide as the field name, not the data field. The
following change works perfectly:
...
FieldSize := Fields[I].Size;
if FieldSize = 0 then
FieldSize := 10;
FieldWidth := ppGetSpTextWidth
(ppFields[I].Font,
StringOfChar('X',FieldSize));
...
I will have to make some changes to better handle the data types which
return a size of zero but it is working now.
Thanks again.
Sidney
On Fri, 28 Jun 2002 10:17:32 -0500, "Alexander Kramnik \(Digital