Saving and loading a WPRichText.TextObjects looses it's name

  • Saving and loading a RTF document containing a WPRichText.TextObjects looses it's .Name property.

    Here is an example:

    Code
    var  _obj: TWPTextObj;  _img: TWPOImage;  _width, _height: Integer;begin  _img := TWPOImage.Create(WPRichText1);  _img.AssignBitmap(Image1.Picture.Graphic);  _width := MulDiv(Image1.Picture.Width, 1440, WPScreenPixelsPerInch);  _height := MulDiv( Image1.Picture.Height, 1440, WPScreenPixelsPerInch);  // Create the actual WPTools image object.  _obj := WPRichText1.TextObjects.Insert(_img, _width, _height, 'IMAGE_NAME');end;

    Now if I display all objects name with the following code, I can see my 'IMAGE_NAME' object:


    Now, if I save this RTF document with WPRichText1.SaveAs and reload it with WPRichText1.Load, and call my DisplayAllObjects procedure, the object is found but it's name is blank.

    Can you pleae tell me if this is a bug. If you think this is not a bug, then tell me what I am doing wrong. I absolutely need the retrieve the .Name property after the loading a RTF document containing an image object (the .Name property works properly for input fields and merge fields.).


    Note: Using the WPRichText1.InsertGraphicDialog causes the same problem.


    Michel

  • The .Name property is preserved when I use InputEditField, InputMergeField or BookmarkInput.

    Why is the .Name property not preserved when using TextObjects.Insert ?

    How can I have an image in the RTF document that will preserve it's .Name property when I reload the RTF document ?

    If the .Name property is not preserved, is there another property that I can use that is preserved when I reload the RTF document ?

    Also, if I look in the .RTF document with a text editor, I can see the .Name property in the actual RTF document.


    Michel

    • Offizieller Beitrag

    Hi,

    Bookmarks and hyperlinks use the name propetry in RTF and saved as fields, although WPTools always use the TWPTextObj class.

    With images the Name and Source property is saved as

    propietary \*\wppicname and \*\wppicsource. Loading the RTF in a different RTF reader will ignore this names.

    Tose properties are loaded by the RTF reader here:

    txtobj := PrintTextObj(wpobjImage, FPictureName, '', false, false, false);
    txtobj.Source := FPictureSource;

    Regards,

    Julian

  • If I create an image called 'MY_IMAGE_NAME' with

    Code
    _obj := WPRichText1.TextObjects.Insert(_img, _width, _height, 'MY_IMAGE_NAME');

    and save the RTF document. After reloading the RTF document, if I have an OnTextObjectDblClick event and I double-click on my image, the OnTextObjectDblClick event is called but both the pobj.Name (TWPTextObj) and the obj.Name (TWPObject) parameter are empty.

    I was expecting the name of the object 'MY_IMAGE_NAME'.

    How can I retrieve the .Name property that was used when I did TextObjects.Insert.

    Note: This works properly if you don't save and retrieve the RTF document.


    Michel

  • Can you please tell me if this is a bug or not ?

    If this is not a bug, can you please tell me how to retrieve the object name that was used when it was created with TextObjects.Insert. Maybe I need to create my image object with another method ?

    I absolutely need to retrieve the object name that the user double-clicked on so that my other code works properly.


    Thanks,


    Michel

  • In the CloseDestination method of unit WPIOReadRTF.pas I found the code that you are talking about

    Code
    txtobj := PrintTextObj(wpobjImage, FPictureName, '', false, false, false);
            txtobj.Source := FPictureSource;


    But if I put a breakpoint, I see that both FPictureName and FPictureSource are empty.

    Is this a bug ? I have version 5.23.3. Maybe this has been fixed in the latest 5.25 version ?

    Thanks


    Michel

    • Offizieller Beitrag

    Hi,

    FPictureName should be filled here:

    FPictureName := FCurrentExString.GetString;

    I used this code

    ShowMessage( WPRichText1.SelectedObject.Name );
    WPRichText1.SelectedObject.Name := 'TESTNAME';

    In the current version after save&reload in RTF format I get the expected message box "TESTNAME"

    Can you try with your objects, maybe they behave differentlöy. I tried a simple embedded BMP

    Julian

  • If I trace my application here is what I get (WPIOReadRTF.pas):

    In the TWPRTFReader.CloseDestination method FPictureName is assigned properly:

    Code
    FPictureName := FCurrentExString.GetString;

    But then the TWPRTFReader.ChangeDestination (called from TWPRTFReader.Parse) method gets called which erases the FPictureName (I don't know why your are doing this):

    Code
    FPictureName := '';

    Then the TWPRTFReader.CloseDestination method gets called again with the following code:

    Code
    txtobj := PrintTextObj(wpobjImage, FPictureName, '', false, false, false);

    But FPictureName was erased just before in the TWPRTFReader.ChangeDestination method.


    Here are the exact steps to reproduce this problem:

    1- Create an image with WPRichText1.TextObjects.Insert(_img, _320, 200, 'BUG_IMAGE');

    2- Save your RTF document. (Note that in my application I use another extension than RTF. I also tried this with the RTF file extension and I still have the problem)

    3- Clear your RTF document.

    4- Load your saved RTF document. TWPRTFReader.ChangeDestination method gets called and erases FPictureName (this is the actual bug I think).

    5- Create an OnTextObjectDblClick event with some code and put a break point.

    6- Double-click on your image and you should be in your breakpoint in the OnTextObjectDblClick event.

    7- Inspect the parameter pobj.Name (TWPTextObj). You will see that it is empty.


    Please try to duplicate this bug and then tell me how I can make this work.

    Thanks


    Michel

  • As confirmed by Julian, this is a bug that will be fixed in version 5.25.1

    This bug only happens with WriteObjetMode = RTF.


    You can fix this in WPIOReadRTF by commenting two lines:


    Thanks Julian for this fix.


    Michel