OnFieldGetText Event

[Top]  [Chapter]  [Previous]  [Next]

This event is used by the reporting engine to read field values. It is also used by the mail merge function.


Declaration C#

void OnFieldGetText(Object Sender, int Editor, string FieldName, IWPFieldContents Contents)


Declaration OCX

OnFieldGetText(ByVal Editor As Long, ByVal FieldName As String, ByVal Contents As WPTDynInt.IWPFieldContents)


This event is use by the mail merge feature (see Memo.MergeText) and the reporting engine (see interface IWPReport).


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.


VB6 Example:


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'

End Sub



C# Example:


Random rnd = new Random();


private void wpdllInt2_OnFieldGetText(

 object Sender,

 int Editor,

 string FieldName,

 IWPFieldContents Contents)


  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.


To create a hyperlink inside the field use InputHyperlink. You can also load a file with formatted text using LoadText


To create a table with data inside the field execute AddTable. The event OnCreateNewCell can be used to format and fill each new cell.


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.

In this case the property IsMergefield  =false. Use Contents.ExecStrCommand to modify the field state property.

[idh_wpdllint_onfieldgettext.htm]    Copyright © 2007 by WPCubed GmbH