WPCubed Product Support

Get RTF from mailmerged field

I do "cascading" mailmerge!

I had put option into program to edit editfields and merge the editfields and mergefields again.

I create a MergeEngine class to merge the document.

procedure TMergeEngine.DoMergeGetText(Sender: TObject;  const inspname: string; Contents: TWPMMInsertTextContents);begin  FCampo.LoadFromWPObj(Contents.StartInspObject);  if (FCampo.Tipo = cTC_Modelo) then  begin    Contents.Options := [mmMergeAsRTF];    Contents.StringValue := SubMerge(FDataEngine.DoGetValue(InspName), FCampo)  end else    Contents.StringValue :=      FormatValue(FDataEngine.DoGetValue(InspName), FCampo);  FCampo.SetVariable(cMerged, 'True');  Contents.StartInspObject.Source := FCampo.ConfigToString;end;

On merge, when (FCampo.Tipo = cTC_Modelo) Contents.StringValue is a formatted text ('{\rtf1\ansi\deff0\uc1\ansic.......MAL -\par'#$D#$A'}}')

All ok here, but i need that the user can change some field of database and he could remake the merge, but not lost changes that he did out of fields!

Then I create a ReadConfig class to read fields of merged document:

procedure TReadConfig.DoMergeGetText(Sender: TObject;
  const inspname: string; Contents: TWPMMInsertTextContents);
var
  index: integer;
  sValor: string;
begin
  sValor := '';
  if wpobjWithinEditable in Contents.StartInspObject.Mode then
  begin
    FCampo.LoadFromWPObj(Contents.StartInspObject);
    if (FCampo.Tipo = cTC_Modelo) or not
      FCampo.GetVariable(cValor_Original, sValor) then
      sValor := Contents.StringValue;
    index := FEnviroment.IndexOfName(inspname);
    if index <> -1 then
      FEnviroment[Index] := inspname+'='+sValor
    else
      FEnviroment.Append(inspname+'='+sValor);
  end;
end;

but Contents.StringValue not return a formated text, just a plain text.

How I can get a field content as RTF formated?

I tried put Contents.Options := [mmMergeAsRTF] on TReadConfig.DoMergeGetText but I dont have luck! 🙁

#1 ♥ 0
4.5k Views 3 users read 2 min

I did not really look deep into your problem, but with Julian on vacation I thought I'd quickly mention "Contents.OldFormattedText" that I've used in the past to get the formatted string.

#2 ♥ 0

Thanks, I found Contents.OldFormattedText too in spite of the formated text be a little diferent of what first merge put on stringvalue.

thanks to god, this diference dont change the format! 🙂

#3 ♥ 0
support

Hi,

good you found OldFormattedText - you can also use SelectionAsString - in fact inside the OnMailMergeGetText event the field is actually 'selected'. That is a big difference to WPTools 4' mail merge.

Julian

#4 ♥ 0
This category is archived. No new posts are possible.