发信人: wpf (Itouchthebluesky), 信区: BorlandDev
标 题: quickreport q/a 2
发信站: 哈工大紫丁香 (2001年06月09日20:07:31 星期六), 站内信件
Q. How do you use the FORMATNUMERIC function, I can't find a help files to
help me?
A. This function is a wrapper for Delphi's FormatFloat() function.
------------------
Q. Is there an expression that will permit grouping by month? The underlyin
g database has a date field.
A. You have to pass in an expression that would be the month, the easiest w
ay is to use a calculated database field that would be the year and the mont
h (unless you want the same month from multiple years grouped together.
------------------
Q. I want to have a database field as the expression, but the table is not
available to me at design time and adding <tablename>.<fieldname> to the exp
ression string at run time doesn't work.
A. To define an expression at runtime, you must define it before the report
starts. Group bands initialize their expression at the start of the report
and you can not change the expression while the report is running. This li
mitation will be removed in a future release.
------------------
Q. I couldn't find any information for the meaning of the "arguments" param
eter in the RegisterQRFunction
A. The last parameter is used for the expression builder to know what
group to put the function in and what parameters to accept.
First is the group (1-6), followed by one character for each
parameter.
1NN would be in the first group (don't remember which one), with two
numeric arguments.
2SNB would be in the second group, three parameters (text, numeric
and boolean
------------------
Q. Expression wont work if the field name has a space or a hyphen in it
A. The expression parser will not work with field names with spaces or hyph
ens in it. This is a limitation that we try to fix in a future release. Th
ere are a few simple workarounds for this. One way is to use a TQuery contr
ol and rename the field name in the SQL statement. If you have to use a TTa
ble, create a calculated field based that equals the original.
(QR3) With Quick Report 3, you can use fields with spaces in TQRExpr express
ions if the field is enclosed in square brackets like '[Table1.Field 1]'.
------------------
Q. My function doesn't work I want to use:
if (table1.field1 = '', 'Blank', table1.field1)
to output the text "blank" when the field is blank or null
A. Change "if (" to "if(" and the function will work.
------------------
Q. I can't sum TTimeFields?
A. TTimefields get converted to strings by the expression evaluator which p
revents the report from doing
math operations on it. A future release will have a a function to 'conv
ert back' to a float.
------------------
Q. Expressions are being evaluated from right to left
A. This will be addressed in a later release. The work around is to use par
entheses
------------------
Q. The following expression always returns 0: SUM(IF(Query1.CartonID='SI',
Query1.Caliper, 0))
A. Change the 0 to 0.0 and the SUM() function will work correctly.
------------------
Q. Why doesn't the expression Count(Table1.Field1) return the right value?
A. The Count function in the expression builder returns a number that incre
ments by 1 with every call to Count. It does not behave like the SQL Count(
) function that counts the variable passed to the function. If you click on
Count in the expression builder you should see "Increments for each iterati
on" appear under the Count label as the function's description.
-----------
Q. How do I check the value of QRExpr control at runtime?
A. The "Value" property of a TQRExpr component is of type TQREvResult, whic
h is defined in qrprntr.pas. You can check "Value.Kind" to see what the dat
atype is. The following table shows how to retrieve the results of the expr
ession based on the value of "Value.Kind"
If Value.Kind = resInt then the results of the expression are in Value.I
ntResult
If Value.Kind = resDouble then the results of the expression are in Valu
e.DblResult
If Value.Kind = resString then the results of the expression are in Valu
e.StrResult (defined as string[255])
If Value.Kind = resBool then the results of the expression are in Value.
BooResult
If Value.Kind = resError then the expression had an error
------------------
Q. I use QRExpr to calculate the Average of a currency field but it shows a
s numerical, not currency.
A. This is a known limitation of the QRExpr control. You can have the cont
rol display the currency character by using the mark property and set the ma
sk to something like '$,###.00'. The QRExpr control's mask is the format st
ring used by FormatFloat() and FormatDateTime functions. Please refer to th
eir documentation for allowable values.
------------------
Q. Why does my report crash when I use TQRExpr controls under Delphi 1? Th
e same report runs fine when I compile it with Delphi 2.
A. Delphi 1 uses a lot of stack space when you use nested expressions with
the TQRExpr control. This is why we suggest that you raise the stack size a
s high as Delphi 1 will let you go for your project. We allocate all of our
expression variables from the heap. but Delphi 1 still uses stack space to
handle the multiple function calls required to evaluate the expressions. Wi
th Delphi 1, some expressions are bettered handled by adding code to calcula
te the results instead of using the TQRExp control.
------------------
Q. I have a simple query that uses the SQL COUNT(*) and I am?trying to disp
lay it in a QRExpr component but it is not displaying that field.
A. The SQL COUNT(*) is conflicting with the QR COUNT function. You will ha
ve to alias the column or use a QRDBText to output the field.
------------------
Q. I can't get the QRExprMemo to display more than 255 characters when I us
e Delphi 1.
A. The number of characters in a QRExprMemo is limited to the maximum strin
g size. In Delphi 1, the maximum string length is 255 characters.
------------------
Q. How can I count frequencies of the values in a dataset field?
A. You can do this with expressions like:
SUM(IF(Table1.GENDER = 'M', 1, 0)) and SUM(IF(Table1.GENDER = 'F', 1, 0))
------------------
Q. How can I get the dataset of the report to display in the QRExpression i
f the dataset is on a separate form?
A. You will need to add the dataset to the report, using the report's AllDa
taSets property. The expression will not work at design time, but it will w
ork at runtime.
Example:
Form1 has a dataset named tbCountry with the field 'Capital' in the table.
Form2 has a report named QuickRep1 with a qrexpr control on the summary band
.
You want qrexpr to read the capital field of the tbCountry dataset.
You would have form2 use form1 and in the report's BeforePrint event you wou
ld add the tbcountry table to the report with the following syntax:
procedure TForm2.QuickRep1BeforePrint(Sender: TQuickRep;
var PrintReport: Boolean);
begin
with quickrep1.AllDataSets do
if IndexOf(Form1.tbCountry) = -1 then
Add(Form1.tbCountry);
end;
The QRExpr.Expression property would be set to tbcountry.capital
------------------
Q. I want to sum a field, but I need to ignore the highest and lowest value
, can this be done?
A. You can do this by using the expression 'SUM(Field)-MIN(Field)-MAX(Field
'. Please note that if you only have two records, the sum will be zero.
------------------
Q. What are the allowable datatypes that can be used in a TQRExpr control?
A. The allowable Delphi datatypes that can used in a TQRExpr control (or Gr
oup expression) are longint, double, string[255], and boolean. Currency fie
lds are stored as double. Date and time fields are stored as string.
------------------
[Frames]
==================
Q. How can I separate the letters from the top of the frames with a QRDBTex
t control?
A. The current release provides no control over the relative positioning of
the frame in regards to the text. You can get finer control by using a QRS
hape control and place it underneath the text control.
------------------
Q. Setting DrawBottom to true of the report's Frame property of works on pr
eview, not when printed.
A. The default bottom margin of a report goes beyond the printable area of
many printers. If you set the bottom margin to a greater value (try 1.0 in
as an example), you should see the bottom frame.
------------------
Q. Some lines do not appear in the preview, but they appear in the printout
.
A. The report is rendered to a TMetafile object when it is sent to the prev
iew. Depending on the zoom value of the preview, the scaling of the TMetafi
le may crop out some of the lines. If you zoom in (you may need to use a cu
stom preview to zoom in close enough), the lines will reappear.
------------------
[Groups]
==================
Q. How do I print a group footer band?
A. Add a TQRBand, set it's type to groupfooter and link to rbGroupFooter.
You would then link it to TQRGroup band by the footerband property. The new
band will print at the end of the group of detail band.
------------------
Q. Is there an expression that will permit grouping by month? The underlyin
g database has a date field.
A. You have to pass in an expression that would be the month, the easiest w
ay is to use a calculated database field that would be the year and the mont
h (unless you want the same month from multiple years grouped together.
------------------
Q. I have a billing report. In the group-footer I take the sum of the amoun
ts. I print it at the summary . Now I would like to print the intermediate-r
esults of the amounts at the end of each page (except at the end of the last
page). How can I do it?
A. You would put the TQRExpr component to handle the amounts on a page foot
er band. Set the QRExpr's ResetAfterPrint to true so that the total will ge
t reset after each page. To suppress the final page footer, set the report'
s Options.LastPageFooter to true.
If you want to have a page footer on the last page, but want to suppress the
output of the last page's total, one easy way to tell that you are on the l
ast page is to use a summary band. It will be called before the last page f
ooter and you can use it's BeforePrint event to set a flag to prevent the ou
tput of the final QRExpr total. If you don't need a summary band, set it's
height to 0.
------------------
Q. When I have a group header for a sub-detail band, the header gets printe
d twice for the first record and only once for every record thereafter.
A. If you just want a group header band to print for each set of subdetails
, do not use a TQRGroupband, that band is for when you want to break up the
data in groups. Just set the subdetail band's Bands.HasHeader to true. Thi
s will add a band of type TQRBand and it will only print at the start of eac
h set of subdetails. This is documented on page 5-73 of the manual under th
e topic "BANDS PROPERTY FOR TQRSUBDETAIL".
------------------
Q. TQRGroup does not work with an expression on a queryfield if the query c
omponent is not on the report form.
A. The dataset must be either on the form or on the report's datamodule.
------------------
Q. A new page is not generated on the GROUPHEADER if the current page numbe
r is 1 (one) and the Property NewPage is TRUE. It will work fine if this oc
curs on page number 2 or higher.
A. QuickReport was designed to ignore the first ForceNewPage band if that b
and is on the first page. To get around this, set ForceNewPage back to fals
e and call the report's NewPage method from the BeforePrint event of that ba
nd like the following:
procedure TfrmGroupTest.QRGroup1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
Quickrep1.NewPage;
end;
------------------
Q. How do I set a group expression to break on multiple fields?
A. Set your group band expression to 'Query1.Field1 + Query1.Field2', if th
ey are strings. If they are not strings, convert them to strings first usin
g the STR() function. If that does not work, you can create a Calculated Fi
eld in your Dataset that is a combination of the fields and have the group.e
xpression use that field.
------------------
Q. We query our data grouped by a field and is there any neat way to get th
e text "to be continued" to the bottom of the page if the group is several p
ages, i.e. how do we know before page change the last row was not the last r
ecord in the group?
A. There isn't a "neat" way to do this with the current version. You may w
ant to add with some code to the BeforePrint event of the page footer band.
You could check the next row in your dataset to see if the group changes.
Just remember to leave yourself in the original row of the dataset so that y
ou don't skip any rows.
------------------
Q. How do I get group headers to print after a page break?
A. Group bands in Quick Report 3 have a ReprintOnNewPage property to do thi
s. With Quick Report 2, you can emulate repeating group headers through cod
e and some duplicate bands. An example program that shows how to do this can
be downloaded from our web site. Look for the file "repeats.zip".
------------------
Q. How do I create a group band at runtime?
A. Before the report starts, you can add a group by creating a control of t
hat type and setting some of it's properties. The following code would add
a group band to a report using the orders table
procedure TfrmCreateControls.FormCreate(Sender: TObject);
begin
{ Create the group on this form }
QRGroup1 := TQRGroup.Create(Self); { QRGroup1 defined as TQRGroup in the f
orm declarations}
with QRGroup1 do
begin
{ assign it to this report }
Parent := QuickRep1;
{ assign it to the detail band }
Master := Parent;
{ Set it's expression }
Expression := 'CustNo';
end;
{ Now add a text control to this band }
with TQRDBText.Create(Self) do
begin
Parent := QRGroup1;
Dataset := QuickRep1.Dataset;
DataField := 'CustNo';
end;
end;
------------------
Q. I have several Group Bands in my report. How is it possible to change th
e printing order of these bands at runtime. Eg. at case one I need to print
only Group1, case two Group2, Group 1, Group 3, case three Group 4, Group 2
etc. The order is told by end user at runtime.
A.?QuickReport uses the creation order of the group bands to set the order a
t runtime.?You can change the ordering of the group bands by calling the the
ir SendToFront and SendToBack methods.
------------------
[Images and Shapes]
==================
Q. My images do not print consistently.
A. This can happen for a few reasons. If you are using a TQRDBImage and th
e images do not always print, it may be a problem with how the BDE is handli
ng the BLOB data.
Instead of using a TQRDBImage, use a TQRImage and a TDBImage. Assign the da
tabase bitmap to the TDBImage (you will need to add a TDataSource to assign
the field to the TDBImage). In the BeforePrint event of the band that conta
ins the TQRImage, assign the TDBImage's bitmap to the TQRImage's bitmap.
Example:
procedure TfrmImageTest.DetailBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
qrimage1.picture.bitmap.assign(DBImage1.Picture.Bitmap);
end;
If you are using a TQRImage and loading the image directly into the componen
t does not work, try loading the image into a TBitmap and then copying the d
ata to the TQRImage component.
Example 1:
MyBitmap.LoadFromFile(somefile); // MyBitmap is a TBitmap that is created
and freed somewhere else
QRImage.Picture.Bitmap.Assign(MyBitmap);
Example 2:
MyBitmap.LoadFromFile(somefile);
QRImage.Picture.Bitmap.Height := MyBitmap.Height;
QRImage.Picture.Bitmap.Width := MyBitmap.Width;
QRImage.Picture.Bitmap.Canvas.Draw(0,0, MyBitmap);
--
据说呆娃儿不笨
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.245.166]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:210.395毫秒