| RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To |
| Quick Reports Tutorial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Page 5: Using Calculated fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Using Calculated fields Since the creation of calculated fields in a table is beyond the scope of our tutorial, I will concentrate on using the QREXPR component. This component is fairly complex and complete in it's design but like many parts of QR it has it's quirks. The result screen in the expression builder is the memo field at the bottom of the dialog. By selecting an item in each of the sections and pressing the ADD key there you build the expression. The QREXPR has four sections:
Constant: This section is used to handle a number or string in an equation. For example, let's say you need to multiply a field by a number to get your calculated field. You would enter the number (.05) in the edit field. Leave the drop down box as numeric and press the Add button. This places the number in the bottom memo field.
Operators: This section, like the constant section, is used to add operators to the field. For example, by pressing the * button you add the * to the equation you began with the number .05. The operator section behaves much like a calculator with the ability to also handle parentheses and Boolean comparisons in your equation as well as all the other math keys.
Data Field: The data field section allows you to select a field from any table used in the report. Therefore you have a Dataset dropdown box to select your table and a listbox to select the field. One caveat: When you are building your expression, every time you add something to the expression it returns to the top of the list of tables. So be careful you have the right table and field when you press the Add button. To continue our example, you can now select a field to multiply .05 to and press the Add key to add it to the memo field. If you now press the OK button to close the dialog, you can see your expression in the Expression property of the component. By reclicking the 3 dots, you will bring the expression back into the expression builder but you can't get at it to edit it. The only way to change an equation you created is to carefully modify the string in the expression property. Otherwise you need to clear the equation and start over.
Function: This category contains a large selection of options available. Some will probably be rarely used. Others can be duplicated in code with out using the expression component. But some are essential. Here is what is available:
Note: Functions with *s are designed to be used in IF expressions. The usage example explains any other possiblities.
Working with the IF function can be the most frustrating because you can't get at the actual statement you are building. Remember, you can edit the string outside the dialog box, so if necessary, just exit out of the Expression builder and carefully make your changes.
TIP #8 $###,###,00 for Currency , EUR##0.00 for Eurodollars.
You can also setup different masks for positive and negative numbers by placing a semicolon between them. For example: $##0.00;($##0.00);
Next page > Sorting, Grouping and Summarizing in Reports > Page 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time. · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC. |
|
· NEXT ARTICLE:
Your application will be shut down!. Access violations, invalid page faults, general protection faults; the name changes, but the nature of the problem is always the same. Find the solution to your Delphi AVs. |
| Stay informed with all new and interesting things about Delphi (for free). |
|
|
| Got some code to share? Got a question? Need some help? |

