InputMergeField Parameters- Can I store Format in Command?

  • I am working with the Mail Merge and trying to get a handle on how to specify formatting for numeric fields. I'm getting a little confused by the difference in names between the objects and the documentation. I'm posting this here to try and get confirmation that I am using these objects correctly and if so maybe it can be helpful to others.

    InputMergeField takes the following paramaters: (The following is from the WPTools help file)

    Zitat

    FieldName: string the name of the field
    DisplayText: string the default text for the field. It is stored in txtobj.Params
    Command: string the optional commands for the field - they will be stored in txtobj.Source.
    Format: Integer an optional value to specify the format. It will be stored in txtobj.IParam.
    DisplayChar: Integer an optional which will be attached to the field. It will be stored in txtobj.CParam. It should not be used.

    What I really want is to store a format string. There is a field called Format and I guess I could define a set of integers for some fixed formats but "Command" looks like a better option to me.

    DisplayText is confusing to me. I found that it does Initially set the default value. However, if the text shown in the field is edited in the document then Params is not updated. And if Params is updated on the Merge object the text in the document is not changed. I'm not sure when Params would ever be used after the initial call to InputMergeField.

    So in my Template Editor I have two boxes. One to enter a field name and one to enter a format.

    I have two events to deal with field. When the cursor position changes if I am on a field copy the field information to my input boxes:

    Code
    procedure TAgToolsEditor.WPRichTextChangeCursorPos(Sender: TObject);var  CurrentField: TWPTextObj;begin  CurrentField := WPRichText.FieldAtCP;  if CurrentField <> nil then  begin    cboCustomField.Text := CurrentField.Name;    cboFormat.Text := CurrentField.Source;  endend;

    Then I have an "Add Field" button will either update or insert a new field. When updating a field I am re-setting the Params field. However that does not seem to matter. The text I see in the document will not change.

    Code
    procedure TAgToolsEditor.cmdAddCustomClick(Sender: TObject);var  CurrentField: TWPTextObj;  DefaultText: string;  i: integer;begin  CurrentField := WPRichText.FieldAtCP;  if CurrentField <> nil then  begin    CurrentField.Name := cboCustomField.Text;    CurrentField.Params := cboCustomField.Text;    CurrentField.Source := cboFormat.Text;    WPRichText.ReformatAll(false, true);  end  else  begin    i := LastDelimiter('.',  cboCustomField.Text);    if (i > 0) then      DefaultText := RightStr(cboCustomField.Text, Length(cboCustomField.Text) - i)    else      DefaultText := cboCustomField.Text;    WPRichText.InputMergeField(cboCustomField.Text, DefaultText, cboFormat.Text);  end;end;


    Then in my merge code I pull out the Format string. Now stored in a "Command" field instead of the source property we used above.


    • Offizieller Beitrag

    Please note that file fields are created as TWPTextObj objects. This objects have the properties "Name" and "Source".

    TWPTextObj are used for all kind of objects, fields, hyperlinks, objects etc. In case of mergefields the name is the fieldname, "source" is the command, a string which can be used by You to save additional parameters.

    You have access to the TWPTextObj in the event though Contents.StartTag.

    "DisplayText: string the default text for the field. It is stored in txtobj.Params"
    This is actually optional - the "params" string is normally used by the textobjects such as datefield or time.