WPCubed Product Support

Mail Merge changes margins

I am doing a mail merge by instantiating a TWPRichText in a class (not putting it on a form), assigning an RTF template, using a TWPMMDataProvider (also not on a form) and doing the usual mail merge routine as described in the manual.

After the mail merge the output TWPRichText has different left and top margins than the input document.

The mail merge template had \margl1788 and \margt773. The resulting document had \margl1882 and \margt1440.

It seems to me that the resulting values are the default values which is not what I want.

I tried assigning the header of the template

FMailMergeQry.Open;
  FMailMergeQry.First;
  try
    i := 0;
    lAllRichText.BeginUpdate;
    while not FMailMergeQry.Eof do
    begin
      lTemplate.MergeText;
      if i=0 then // FIRST RUN
      begin
         lAllRichText.AsString := lTemplate.AsString;
         lAllRichText.Header.Assign(lTemplate.Header); // <- DIDN'T WORK
         lAllRichText.CPPosition := MaxInt; 
      end
      else if i>0 then // SUBSEQUENT RUNS
      begin

but that didn't work either. Calling Loaded() after assigning AsString also didn't help.

Do you have any idea what am I doing wrong?

#1 ♥ 0
3.1k Views 2 users read 2 min
support

Hi,

Did You call "Loaded" fro the dynamically create TWPRichText? If not, it is possible that it thinks it is still being loaded.

Also, better use TWPCustomRTFEdit.CreateDynamic.

lAllRichText.AsString := lTemplate.AsString;

Is a bit difficult to debug.

Why not use

mem := TMemoryStream.Create;
lTemplatel.SaveToStrem(mem);
mem.Position := 0;

wp.LoadFromStream(mem, true);

BTW.: If you use the TWPRichText in a class using the TWPMMDataProvider is rather unexpected. I personally would subclass the TWPCustomRTFEdit class and override the method

procedure MailMergeCallBack(Sender: TObject; const inspname: string; Contents: TWPMMInsertTextContents); virtual;

#2 ♥ 0

Thanks Julian, you put me on the right track.

I looked at the output after the mail merge and there the margin was still correct. After assigning it to the editor to display it it went wrong.

I used

rtfAllPreview.SelectionAsString := ...

because it could happen that rtfAllPreview has already some content. Now I check before assigning. If it is empty I assign with

rtfAllPreview.AsString := ...

otherwise

rtfAllPreview.SelectionAsString := ...
#3 ♥ 0
This category is archived. No new posts are possible.