WPSuperMerge and Bitmap merge substitution

  • Hi to all,

    i have a Template rtf document with some "Merge-fields". For one of this i need to substitute the field with a Bitmap image readed from a BMP file.

    I write this code:

    1) On my class constructor (C++Builder) i read the bitmap and stored it on a TBitmap object:

    FBitmapLogo = new Graphics::TBitmap();
    String logoFile = ExtractFilePath(Application->ExeName) + "Logo.bmp";
    if ( FileExists(logoFile) )
    FBitmapLogo->LoadFromFile(logoFile);

    2) On event OnGetText i assign the bitmap to a new TWPOImage object and set Contents->Obj:

    void __fastcall TMailMergeEngine::SuperMergeGetText(TObject *Sender,
    const AnsiString fName, TWPInsertTextContents *Contents)
    {
    if ( fName == "LogoGrafico" )
    {
    TWPOImage * obj = new TWPOImage(WPMerge);
    obj->Picture->Bitmap->Assign(FBitmapLogo);
    obj->HeightTW = MulDiv(obj->Picture->Bitmap->Height,1440,Screen->PixelsPerInch);
    obj->WidthTW = MulDiv(obj->Picture->Bitmap->Width,1440,Screen->PixelsPerInch);

    obj->WriteRTFMode = wobOnlyRTF;
    Contents->Obj = obj;
    }
    }

    But non Bitmap are displayed on my report.

    I missing something ?

  • Hi,
    i have modified my code as your reply:

    TWPOImage * obj = new TWPOImage(WPMerge);
    obj->Picture->Bitmap->Assign(FBitmapLogo);
    obj->HeightTW = MulDiv(obj->Picture->Bitmap->Height,1440,Screen->PixelsPerInch);
    obj->WidthTW = MulDiv(obj->Picture->Bitmap->Width,1440,Screen->PixelsPerInch);

    obj->WriteRTFMode = wobOnlyRTF;
    Contents->Options = (Contents->Options << mmInsertObject);
    Contents->Obj = obj;

    But a compiler error stop me now:

    [C++ Error] WpEngineU.cpp(202): E2094 'operator<<' not implemented in type 'TInsertTextOptions' for arguments of type 'TWPMailMergeContinueOption'
    [C++ Error] WpEngineU.cpp(395): E2096 Illegal structure operation

    I see the help and object TWPInsertTextContents don't have flags mmInsertObject.
    Only in TWPMMInsertTextContents i see this flags but how can i set it from SuperMerge->OnGetText event ?

  • Hi Julian,

    don't work also with a temporary variable.

    From WpTools help i see:

    TInsertTextOption type

    Code
    UnitWPMergeDeclaration TInsertTextOption = (    wpinsTrim,    wpinsMaxLength, { Use 'FMaxLength' }    wpinsIgnoreTrailingSpacesIfEmpty, { Skip Whitespaces behind if empty }    wpinsIgnoreParIndents, { Only for RTF Input - Ignore spacing, shading, ... }    wpinsIgnoreParSpacing,    wpinsIgnoreParAlign,    wpinsIgnoreParColor,    wpinsIgnoreParTabs,    wpinsIgnoreParNumbering,    wpinsIgnoreParID, { also sets or delte parProtected flag! }    wpinsIgnoreFonts, { Only for RTF Input - use current font }    wpinsIgnoreFontSize, { Only for RTF Input - use current fontsize }    wpinsReadFromRTFText, { copy from CP as much text as fits to the destination }    wpinsFormatRTFToPosition, { moves the loaded text to the current insentation (first indent!)  V3.12a }    wpinsKeepOriginalText    );

    As you can see no mmInsertObject are present in this set.

    For find mmInsertObject declaration i must search TWPMMInsertTextContents Object and then i can read that on WpTools help:

    Code
    UnitWPRtfIODeclarationTWPMMInsertTextContents = class(TObject)DescriptionOne instance of this class is passed to the OnMailMergeGetText event to let the event modify or read out the merged text. The component TWPMMDataProvider can be used to automatically handle the data transfer. CategoryEditField SupportMailmerge Support

    TWPMMInsertTextContents options Properties:

    But i canno't find any instance of TWPMMInsertTextContents class passed to the OnMailMergeGetText event

    • Offizieller Beitrag

    The wpmerge.pas supports different optiuons, thats true. (In V5 this has changed, both use same parameter)

    Here it is sufficine to set the obj parameter - please check the source in wpmerge.pas, line 1935 ...

    there it should go into this code

    else if mrgcont.Obj is TWPObject then
    begin
    location := wplstObj;
    ins_obj := TWPObject(mrgcont.Obj);
    FIgnoreTrailingSpaces := FALSE;
    end

    WidthTW and HeightTW must be defined - I see no way why this should not work,

    but I do not think this is ideal:

    obj->Picture->Bitmap->Assign(FBitmapLogo);


    Better do a LoadFromFile since then the original data is saved in that object.

    Also TWPOImage(WPMerge) is not perfect, that should be owned by the Destinateion, not the source.

  • Hi Julian,

    the source in wpmerge.pas, line 1935 are right.

    i have modified my code as here:

    With debug i follow code execution in my function and all seem ok but the problem are not solved.