Understanding the Calc Tab in the Designer
|
The Report Objects Window | This give you access to all the objects, variables, and procedures used by the report. There are three views that this window can give you, and they are invoked by right click on the pane and selecting from a popup menu:
|
|
The Events View - This displays the hierarchy of all the objects in a report, with the Report Object itself being at the top of the tree. Below this are all the bands in the report and branching off each of these are the components in each band. This is the most used view of the Report View. As you click on each object or band you will see the in the opposite window displays a list of events which are associated with the object or band in question. This is key to the design of the coding model for the Report Designer: as a report is run and processed various events 'fire' and it is possible to write functions which will be called as these events fire. For example, every report object has a BeforePrint event which fires before the visual output is drawn on the screen. So you can use this to, say, set the Detail Band to be invisible if charge associated with an equipment item is 0.00. More about this later, but for now, you can see that if any object has code associated with it then it appears in green; select any one of these objects in the Report Window, and then an entry in the Listings Window opposite that has its icon highlighted. In the Code Window (bottom left) you will see the procedure that will be called when the event associated with the object fires.
|
|
The Module View - You can think of a report as a little programme or module in its own right. This is distinct from the Report Object, which is just one of a collection of things that make up the report module (albeit the most important one). If you select the Module View you will see that it has two nodes:
|
· | Global this has thee parts: Declarations, which allows you to set global variables and constants. If you select this node in the Quote report, then select Variables in the Listings Window opposite, you will see that the Code Window (bottom left) has 3 Boolean types declared; Events, of which there are two (OnCreate, OnDestroy) which fire when the report module is opened and closed respectively. Click on OnCreate and you will see in the Code Window that our three global variables are initialised here.; Programmes, which are event independent procedures that you can define can call at anytime in any other part of the report, i.e. in a procedure that you have linked to a particular event. To create, compile or destroy a global procedure, right click in the Listings Window.
|
|
· | Event Handlers this simply displays in the Listings Window all of the events in the report which have procedures (code) associated with them.
|
The Variables View - This lists all the Report Bands and colours in green any that have a variable component in it. If you select one of these bands the Listings Window displays what variables are owned by the band, and if you select any of these variables then the Code Window displays any procedures that a specifically linked to the OnCalc event of the variable. More about variables later.
|
The Listings Window | We can be brief in this section as we have indicated above how this window works. Effectively, the window acts as a conduit between the Report Window and the Code Window: select any entry/object in the Report Window and the Listings Window will display all of the coding options available to you for that entry/object. If any code has already been written against an event, procedure, variable etc listed then the Listings Window will indicate this and if you select the entry the Code Window will display the procedure, variable declaration etc. In order to create a new procedure to be associated with an entry in the Listings Window, simply select the entry you want to code against then click in the Code Window itself; or you can right click on the entry to see a full set of options / actions that you can perform.
|
The Code Window | Like the name suggests, this is where you right your code. Most of the time the name of your procedure will be defined automatically for you so its just a case of typing between the Begin..End pair that frames the entire procedure. The language used by the code compiler is a subset of Object Pascal (Object Orientated Pascal) and has a very simple syntax. You will need to refer to other sources for an introduction to Pascal if you are completely unfamiliar with the language.
|
|
Once you have written some code it's a good idea to test it before diving straight into a preview of the report; to do this just right click on the Code Window or the entry you are working with in the Listings Window and select Compile. If there are any errors these will be indicated in a small panel at the bottom of the Code Window. A common error is not completing a code statement with a semi-colon (;). To delete a procedure, again you just need to right click on the on the Code Window or the entry you are working with in the Listings Window and select Delete.
|
The Tools Window | This window has two functions: it gives you an insight into all the properties and functions associated with the data, report objects and code objects in the report; and it also allows you to automatically reference these properties and function in your Code Window simply by dragging any listing in the lower panel of the Tool Window onto the Code Window. Let us do an example: suppose you or your staff occasionally forget to enter the main Contact for a Job; when you come to print the Quote this is embarrassingly obvious because the "Dear Contact Name" just says "Dear _______". It would be nice if you could at least substitute the word "Customer" for the empty field. To do this follow these steps:
|
|
· | Set the Report Window to an Events View, expand the Title Band, then select the field object which is used to display the Contact1 data (DBText22)
|
· | In the Listings Window select the OnGetText event. Now click in the Code Window. A new procedure will be defined for you:
|
procedure DBtext22OnGetText (var Text: String);
|
begin
|
Text :=
|
end;
|
· | Set the Tool Window to be on the Data tab. Scroll down until you reach the Jobs-Contact1 entry. Click on the grey panel area of the Jobs-Contact1 entry, drag it to the Code Window and let go on above the "Text :=" line.
|
procedure DBtext22OnGetText (var Text: String);
|
begin
|
List['Jobs-contact1']
|
Text :=
|
|
end;
|
|
· | Now manually type in the remaining code to finish of the procedure to make the procedure thus:
|
procedure DBtext22OnGetText (var Text: String);
|
begin
|
if List['Jobs-contact1'] = '' then
|
Text := 'Customer';
|
end;
|
Right Click on the Code Window and select Compile to check all is ok.
|