|[Top] [Chapter] [Previous] [Next]|
void OnFieldGetText(Object Sender, int Editor, string FieldName, IWPFieldContents Contents)
OnFieldGetText(ByVal Editor As Long, ByVal FieldName As String, ByVal Contents As WPTDynInt.IWPFieldContents)
It is used to fill fields with data during the process of mail merge or report creation. The mail merge is started with MergeText. Inside the merge process the event OnFieldGetText is triggered for all fields.
The provided interface Contents makes it easy to change the text displayed by the field.
It is also possible to read the current text in a field. To do so simply use SaveTo... with the property OnlySelection set to true. This works, because the text of a field is (invisibly) selected while the OnFieldGetText event gets called. Alternatively it is also possible to use Memo.TextCommandStr to delete, read and write fields.
private Sub WPDLLInt1_OnFieldGetText(ByVal Editor as long, _
ByVal FieldName as string, _
ByVal Contents as WPToolsInt.IWPFieldContents)
if FieldName='NAME' then Contents.StringValue = 'Julian Ziersch'
Random rnd = new Random();
private void wpdllInt2_OnFieldGetText(
if (FieldName == "NAME")
Contents.StringValue = "Julian Ziersch";
else Contents.StringValue = Convert.ToString(rnd.NextDouble());
It is also possible to create or update an image which is placed inside the field. To make this as easy as possible there are two functions LoadImage and LoadPicture. Both methods will not simply replace the contents of the field with a new image but reuse an existing image container object.
Hint: In our product WPTools the event with similar functionality was named OnMailMergeGetText.
If you know that you do not need the field after the merge process you can execute DeleteField. The field markers, not the contents will be removed.
An interface to access the current field is provided as property FieldObject. You can use this interface to read other properties of the merge field.
If you are using the Active-X and your developing system does not provide access to the interface passed as parameter, use the property EventField instead.
The event is also used for report group variables in the "add:" mode. Here only the StringValue may be modified. The property FieldObject will be null in this case!
The reporting engine will also trigger the event OnFieldGetText to evaluate fields which were used in band conditions such as ?fieldname=null and ?fieldname#null.