MAILMERGE with images

    • Offizieller Beitrag

    Q: Is it possible to insert a bitmap during a mailmerge? I'd like to have a field called "picture" and in the MailMergeGetText have it output a bitmap.

    A: You can assign a new TWPObject instance to Contents.obj - that will be inserted into the merge field. But is is also possible (and recommended) to use the TWPObject from the previous mail merge run.

    The field is inserted with:
    TemplateEdit.InputMergeField('PICTURE','[img]');

    This is the event handler (simplified, using 2 TImage objects)

    Code
    procedure TWPEdTest.OnMailMergeGetText(Sender: TObject;  const inspname: String; Contents: TWPMMInsertTextContents);var i : Integer;    wpobj : TWPOImage;begin  if inspname='PICTURE' then  begin    // A) - there is no image in this field    if Contents.CurrentObject=nil then    begin       wpobj := TWPOImage.Create(TemplateEdit);       // wpobj.LoadFromFile()       wpobj.Graphic := Image1.Picture.Graphic;       wpobj.WidthTW := wpobj.ContentsWidth;       wpobj.HeightTW:= wpobj.ContentsHeight;       Contents.obj := wpobj;    end    else    // B) There is an image, we replace the contents    begin      Contents.CurrentObject.Graphic        := Image2.Picture.Graphic;    end;  end;end;

    If you need to insert an image from a database you can use code like this (taken from unit WPDBRich = TWPMMDataProvider implementation)