Replace graphic as placeholder

  • Hello,

    in wptools 6 I used graphic objects as placeholders in documents/reports that were later replaced by the real picture using the following code. This allows me to use exact positioning of the graphic elements in the templates.

    for j := 0 to wpView.TextObjects.Count - 1 do begin
    s := uppercase(wpView.TextObjects.list[j].url);
    if pos('.BMP', s) > 0 then
    wpView.TextObjects.list[j].Graphic.Bitmap.LoadFromFile(tempdir + s)
    else
    wpView.TextObjects.list[j].Graphic.LoadFromFile(tempdir + s);
    end;

    This no longer works (wothout error message) in WPTools 7. The contents are not replaces, the placeholder picture stays visible.

    Any help would be VERY appreciated as I have alreaady rolled out the new version and customers complain ;-(( I don't want to go back to V6!

    • Offizieller Beitrag

    Please use
    wpView.TextObjects.list[j]..LoadFromFile(tempdir + s)

    Direct access to Graphic.Bitmap is discouraged and not stable. Graphic is just a container for the data used by the VCL and may or may not be initialized depending on the visualisation of the object.

    LoadFromFile on the other side supports other file extensions (i.e. PNG) and stores the compressed stream separately to the Graphics object which is just a bitmap.

    Zitat

    in wptools 6 I used graphic objects as placeholders in documents/reports that were later replaced by the real picture using the following code.

    It is better to use a callback for this:

    Code
    procedure TForm3.ObjCallback(   RTFData: TWPRTFDataCollectionBase;    RTFDataBlock: TWPRTFDataBlock;    Par: TParagraph;    obj: TWPTextObj;    param: TObject);begin  if obj.IsImage then     obj.ObjRef.LoadFromFile( obj.ObjRef.url );end;procedure TForm3.Button3Click(Sender: TObject);begin  WPRichText1.RTFData.LoopAllObj( nil, ObjCallback);end;

    Especially if it takes longer to load the images I recommend to use the event ObjectPaint.

    Code
    procedure TForm3.WPRichText1TextObjectPaint(Sender: TObject; pobj: TWPTextObj;
      toCanvas: TCanvas; XRes, YRes, X, Y, W, H, BASE: Integer;
      PageRef: TWPVirtPage; Modes: TWPTextObjectPaintModes;
      const CanvasExtraAttr: TWPPaintExtraParams;
      var ContinueMode: TWPTextObjectPaintResult);
    begin
    
    
    end;