WPCubed Product Support

On Mail Merge assign Obj or ObjRef?

I am loading an image during a mail merge. I have registered a custom image format that I want loaded. So instead of using the Contents.LoadImageFromFile I am loading my own TPicture object and then assigning the graphic.

I am a little confused when assigning the object. I have three questions:

  1. Can I just assign my WPImage to Obj as in the code below or should I create a text object and then assign Obj := NewWPImage.ObjRef?
  2. Do I need to free the current contents of Obj?
  3. Do I need to set the height and width after setting the Obj?

The code I have below is working right now but I have started out but looking at how Contents.LoadImageFromFile was working. That code is confusing to me and has prompted these questions.

My Code:

MyPicture := TPicture.Create();    try      MyPicture.LoadFromFile(AttachmentDir + DataValue);      NewWPImg := TWPOImage.CreateImage(Contents.DataCollection, MyPicture.Graphic);      PictureWidth := MyPicture.Width;      PictureHeight := MyPicture.Height;    finally      FreeAndNil(MyPicture);    end;    // MaxWidth and MaxHeight are in Twips - I just need to scale them    // to keep the picture in the right proportions     WPScaleWH(PictureWidth, PictureHeight, MaxWidth, MaxHeight);    NewWPImg.WidthTW := PictureWidth;    NewWPImg.HeightTW := PictureHeight;    Contents.Obj := NewWPImg;

From Contents.LoadImageFromFile. When I look at this code I wonder?

  • Why was a TWPTextObj created instead of an WPOImage?
  • Why was o.ObjRef assigned to Obj instead of o directly?
  • When o is freed why is ObjRef still valid?
  • What good does it do to set o.Width and o.Height and then immediately free o? Should that be setting

obj.Width and obj.Height? Is that needed at all since the ObjRef width and height is set?

o := TWPTextObj.Create;
    Result := o.LoadObjFromFile(FileName, FDataCollection);
    if Result then
    begin
      aobj := o.ObjRef;
      Obj := aobj;
      aobj.ScaleWH(abs(w), abs(h), true);
      o.Width := aobj.WidthTW;
      o.Height := aobj.HeightTW;
    end
    else o.Free;
#1 ♥ 0
5.4k Views 2 users read 3 min

I just realized I was only searching the WPTool6 forum. I went back and searched the FAQ WPTools 5 and 6 General forum and found this post:

The example there is assigning a WPOImage object directly to Obj like I am doing, so I guess that is OK. I'm still not sure why the LoadImageFromFile is working like it is, but I guess that really does not matter.

#2 ♥ 0
support

Hi,

TWPTextObj.LOadFromFile uses the file extension to know which image class to create. The file extensions are registered in WPObj_Image.pas, at the bottom.

But TWPTextObj should not be passed as Obj - it will always be created dynamically by the TParagraph (and also destroyed or duplicated if required).

Julian

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