Event OnMailMergeGetText

<< Click to Display Table of Contents >>

Navigation:  Programming > Mail Merge (replace fields with data) and data forms > Update Field (Insert Text from Database) >

Event OnMailMergeGetText

This event is used to modify a field. It can also be used to enumerate fields and also to reads the properties of the field or the embedded text.

 

The event OnMailMergeGetText receives the following parameters:

Sender: TObject - this is a reference to the parent editor

const inspname: String - the name of the field

Contents: TWPMMInsertTextContents - this is the most important parameter. It provides You with an interface to evaluate and manipulate the field and the embedded text.

 

In the easiest case You can use one line of code to assign text to a field:

 

procedure TForm1.DoMailMergGetTexte(

 Sender: TObject; const inspname: string;

  Contents: TWPMMInsertTextContents);

begin

Contents.StringValue := DataSet.FieldByName(inspname).AsString;

end;

 

This code will read the contents of a given field and use it as the embedded text of a field. If the field contains HTML or RTF formatted text the text will be inserted as formatted text.

 

If you need to modify the character attributes (such as font name, font style and color) of the field inside this event, please use the interface MergeAttr.

 

     Attention:        Do NOT call ReformatAll,

         do not move the cursor position,

         do not change InsertPointTextAttr.Hidden inside this event!

 

Example: Display a checkbox:

 

 Contents.MergeAttr.SetFontName

 if data=true then

       Contents.StringValue := #254 // þ

 else Contents.StringValue := #168; // ¨