View RSS Feed

Development Team Blog

Crystal RDC Interface: Finding the right Properties

Rate this Entry
Through Report Designer Component (RDC) you manipulate objects and their properties, and use events and methods available in those objects. You can read more in the Help on the page Understanding the RDC Object Model (under Reference Library | Crystal Reports Development).

Because of that, there might not be a direct way to change something in cCrystal like it was in the old CrystalReport class, i.e. by simply setting a different property in cCrystal; you will have to find what you need in the Crystal RDC documentation working your way through the examples given and the name convention we adopted in Visual DataFlex.

As an example, let’s see how we can find a way to change grouping in a report with which we used GroupField from CrystalReport class.

First, you should use the Help pages Crystal RDC Object Model Overview and Visual DataFlex Crystal RDC Object Model Overview (under Windows Application Development | Reporting | Using Crystal Reports) to see the whole class/object structure. That helps to understand the hierarchy of Crystal objects.

On that page I see GroupNameFieldDefinitions (collection) and GroupNameFieldDefinition (object). That sounds like a good candidate. We search for “report object” in the Help and go to the Report Object page on the Crystal Reports Developer’s Help, click on GroupNameFieldDefinitions and then click on GroupNameFieldDefinition, where it says “The GroupNameFieldDefinition object provides properties and methods for retrieving information on a group name field found in a report […]” and all the properties are Read Only. It does not look like what we are looking for, so we keep on looking.

We go back to the Help to use the Index tab and look for ‘groups’. We find Groups - Working with grouping | Changing the existing group's condition field. On that page we see:

Code:
 
CRXReport.Areas.Item("GH").GroupConditionField = CRXDBField
From that, we learn that we need to change GroupConditionField in order to change the group field and that GroupConditionField is a property of an item of the Areas collection.

If we search for Areas Collection in the Help, we see the properties available for the Areas Collection and we find that “The Areas Collection contains the area objects for every area in the report. Access a specific Area Object in the collection using the Item property.” IOW, GroupConditionField is a property of an Area object. If we search for GroupConditionField in the Help, we confirm that GroupConditionField is a property of the Area object – and we find there all the properties that can be set for an Area object, including SortDirection.

By following the nomenclature rules described in Crystal RDC Imported Classes, we know that GroupConditionField should be called ComGroupConditionField in Visual DataFlex. From the Index tab of the Help, we type ComGroupConditionField and sure enough the property is there. The class it belongs to is called cCrystalArea and all properties we saw before for the Area object in the Crystal Help are listed under their COM name on the cCrystalArea | Properties page.

Now, how do we know how to use ComGroupConditionField and the other cCrystalArea properties? You should first learn which objects you need to go through by following the hierarchy outlined in Crystal RDC Object Model Overview. Once you know the object structure you must follow in order to get to the object containing the properties you would like to read or write, you can check the Order sample (ReportInformationCR.rv) to see an example on how to go through the structure and get where you need. Write a test program and try it out to see if the result is what you seek.

Important! Make sure your research is thorough. Sometimes different parts of the Help will give you different pieces of information. For example, if we type ‘Area’ on the index tab of the Help, we find Areas collection. There we read:
The very top Collection in a report is the Areas collection. By default it contains five Area objects. This is a special kind of collection that you may not use too often (for more information, see The Sections collection).
We go to The Sections Collection to read that
[…] By default, a new report, and thus the Sections collection for that report, contains five sections. Each of the five default sections resides in one of the five default areas—five sections:five areas. When you begin with a blank report, Areas and Sections are essentially the same. So there's little need to reference an area unless you have a specific need to do so.
[…]
Thus, unless you have a special need, you can think of Sections as having Report for a parent. If you have the need, or if you want to be very specific, you can also think of Sections having Area for a parent. However you think of this part of the object model is fine. As long as you have five sections and five areas, you can access Sections through Areas, or you can go directly to Sections. Your code will work either way. […]
What we learned so far is that we may be able to access the properties we need via an Area object or a Section object. So let’s look at the Report object – search for “report object” in the Help and go to the Report Object page on the Crystal Reports Developer’s Help. On that page we see the Areas property and the Sections property, both collection objects. If we click on the Sections Collection, we learn that there is a difference when coming through an Area object versus coming through the Report object:


Sections can come from either the Report Object or Area Object. The Sections Collection is a collection of section objects. Access a specific Section object in the collection using the Item property.
  • When from the Report object, the sections object will contain all the sections in the report.
  • When from the Area object, the sections object will contain all the sections in the area only.
We found one difference already, but could we use Section objects instead of Area objects to get/set what we need? To find out, we click on the Section Object on the Sections Collection page. The properties listed on that page do not include Group properties, so we know we cannot set grouping in the section object.
Note: Keep in mind that the RDC interface is a Crystal piece that we use via COM but we have no control over its behavior. Things documented in the Crystal Help might not work exactly as they describe or might not work at all…

This is basically how you find stuff in Crystal RDC and you should apply this to anything you would like to do to a report at runtime using the RDC interface. I hope it helps you now and in the future.

Comments