简体   繁体   English

运行时报表生成器定位控件

[英]Report Builder Positioning Controls at Runtime

I'm using Delphi 2010 with ReportBuilder 10.04 and have a very basic report with 1 detail band containing 2 TppDBText components (one with bold text and the other non-bold). 我正在使用带有ReportBuilder 10.04的Delphi 2010,并且有一个非常基本的报表,其中包含1个明细带,其中包含2个TppDBText组件(一个带有粗体文本,另一个带有非粗体)。 Both are printing on the report at their specified positions defined at design time, as expected. 两者均按预期在设计时定义的指定位置打印在报告上。 What I need to be able to do is reposition the control to the right as close as possible to the end of the text of the other control (which contains varying text lengths). 我需要做的是将控件重新定位到尽可能靠近另一个控件的文本结尾的右侧(其中包含不同的文本长度)。 Any ideas on how to achieve this? 关于如何实现这一目标的任何想法?

First, for this example to work, set the TppReport's 'Units' property to 'utScreenUnits'. 首先,为了使本示例正常工作,请将TppReport的“ Units”属性设置为“ utScreenUnits”。

I will use City and State fields as an example here, and my dataset is called 'tblCustomers'. 我将以“城市”和“州”字段为例,我的数据集称为“ tblCustomers”。

In the DetailBand's BeforePrint property add the following code: 在DetailBand的BeforePrint属性中,添加以下代码:

// ppCity is a tppDBText report control
// ppState is a tppDBText report control

ppCity.Width := length(tblCustomersCity.asstring) * 10; //adjust 10 based on font size
ppState.left := ppCity.Left + ppCity.Width + 10; // adjust 10 based on font size

You could also do this with calculated fields, but since your first control is bold and your second control is not bold, the above should suffice. 您也可以对计算出的字段执行此操作,但是由于您的第一个控件为粗体,而第二个控件为非粗体,因此上述内容就足够了。

To use a calculated field, simply combine City and State into one calculated field called 'CityState', and in the OnCalcs of the dataset do the following: 要使用计算字段,只需将City和State合并到一个称为“ CityState”的计算字段中,然后在数据集的OnCalcs中执行以下操作:

tblCustomerCityState.asstring := tblCustomersCity.asstring +' '+tblCustomersState.asstring;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM