Multi-lined text display

Top  Previous  Next

We’ll improve the previous example  The “Biolife” table has a “Notes” field, which contains a detailed description of each fish. Update our report by adding this field to it.


At first glance, this would seem to be easy - add a “Text” object to the data band between the existing objects, connect it to the “Notes” field and set the object’s size to 8 x 2.5 cm. However, the report preview is not exactly what we want:




FastReport performed exactly what it was instructed to do. The “Notes” field contains multi-lined text of varying length but the “Text” object displaying the information from this field has a fixed size. This is why some lines appear to be cut off. What can be done about this?


Of course, either the size of the object could be increased or its font size could be reduced. However, this may lead to wastage of space on the output page as some fish have long descriptions, while others have short ones. FastReport has some properties which allow us to resolve this problem.


These properties allow a band or an object to automatically adjust its height to create the necessary space for a given record (row). To achieve this, we just need to enable the “Stretch” property of both the band and the “Text” object. However, that is not quite all, because a “Text” object with  longer text should be able to stretch by itself we’ll need to set some of its other properties too.


The “Text” object can automatically set its height and width to make space for its contents. “AutoWidth” and “StretchMode” can be used for this. “AutoWidth” allows the “Text” object to vary its width so that all the lines make space without splitting any words. This mode is useful when an object has a single text line and when growth to the right will not effect other objects. The “Stretch” property allows the object’s height to grow to accommodate the text without changing the object's width. "Stretch" has several modes which can be selected in the object inspector:


smDontStretch – don't stretch the object (the default)

smActualHeight – stretch the object so it makes room for the whole text

smMaxHeight – stretch the object so that its bottom reaches the bottom of the band in which it is placed - we'll look at this mode later on


Here we are interested in the “Stretch” property of the “Text” object. Enable it using the object's context menu or by setting "StretchMode" to smActualHeight. Also enable the band's “Stretch” property. Preview the report and make sure that everything is now as expected.




As you can see, when constructing the report FastReport fills objects with data and stretches them if “Stretch” is enabled. It then computes the band’s height so each object has enough room. If the band's “Stretch” property is disabled, this height adjustment is not performed and the band is displayed at the height set in the design. In this case we would see that the objects with longer text would still be stretched but the band would not, which leads to overlaying of text, since the following band is displayed immediately after the previous one.