Work with selections

Top  Previous  Next

In WPTools Version 9 the selection and cursor is always moved o the current field. So it is also possible to modify the text at the cursor position directly in the OnMailMergeGetText event. This was strictly forbidden in WPTools 4, since WPTools V5 it can be used carefully:


Insert a picture:

 img := TWPOImage.Create(WPRichText1);




Insert a table:




Insert formatted text

// Delete the current contents of the field


// Get the field default character attributes in 'WritingMode'

 WPRichText1.WritingAttr.CharAttr :=  Contents.MergeAttr.CharAttr;

// And add text with variations of the attributes





 WPRichText1.InputString(' Munich');


Please note that fields are represented by start and end objects (cass TWPTextObj). This objects have several useful properties, including 'EmbeddedText' which can be used to read and write the text between the markers. So if you need to quickly update the field at the cursor position you can set FiedlAtCP.EmbeddedText := 'NewText';


The references to the field obejcts are available in the OnMailMergeGetText procedure:

Contents.StartInspObject and Contents.EndInspObject. Please do not mix up with CurrentTextObject, that is the reference of the first object inside the field. CurrentTxtObject is the reference of the first image object, that is the same as CurrentTextObject.ObjRef.