AsString to AsString has changed?

  • I had been using 5.17.2a, and copying a WPRichText from one to another using something like:

    Code
    WPRichText1.AsString := WPRichText_FLayout.AsString;


    This worked fine when a linked image was contained and later loaded the image using LoadObjFromFile when looping through the text objects.

    However, this does not work with 5.17.4. To copy one WPRichText to another I have to do this:

    Code
    WPRichText1.Assign( WPRichText_FLayout );

    Was this intentional or maybe the proper way all along?
    Eric

    • Offizieller Beitrag

    Hi,

    to copy the text I suggest

    WPRichText1.AsString := WPRichText_FLayout.AsANSIString( 'WPTOOLS' );

    instead of 'WPTOOLS' also possible is 'WPTOOLS-nomergefields' and other format string options.

    I don't really see why it does not work anymore. The load&save procedures have not been changed so much. Maybe it is the selection of the displayed text, try ActiveText := BodyText.

    Julian Ziersch

  • While your suggestion works in some cases, it does not work for mailmerge linked images from what I can see (ObjRef.FileName is an empty string).

    However, I found that if I comment out the following lines starting at line 1221 in WPIOReadRTF.PAS that appears to have been added in 5.17.3, then I can leave all alone and my code works as it has been (just using AsString), and it works even with mailmerge.

    Code
    if obj.StreamName <> '' then //V5.17.3
              begin
                RTFDataCollection.RequestHTTPImage(Self, FLoadPath, obj.StreamName, txtobj);
                // see: procedure TWPRTFReader.LoadLinkedImage
                txtobj.Source := obj.StreamName;
              end;

    What is the purpose of this code? It really hoses up my linked images during mailmerge and AsString to AsString copies from one WPRichText to another.

    • Offizieller Beitrag

    Hi,

    this code is required to load linked images in RTF. If you are using linked images it is important that the base path of the image name is know, otherwise RequestHTTPImage will cause the problem.

    It would be good to use the event OnRequestHTTPImage (dorry for the name, it is basically for HTML support!)

    In this even you can set the last parameter to true to avoid execution of the default code.

    I cannot help more since I don't know which path names the images use (or if they are using pathes at all).

    Julian

  • Thanks Julian... setting Ok := false did the trick in the editor portion of my app... I can keep my paths using a placeholder to be resolved at image load time.

    However, in my mail merge/report generation time, this did not work... but I found if I resolved the path and set the Source equal to the resolved path, then the mailmerge/report creation phase now works as well.

    note: for a reason unknown to me, trying to set the text object's steamname in the OnRequestHTTPImage caused an invalid pointer operation in your CloseDestination routine when it assigns StreamName to the Source, so I had to resolve the path and assign it to Source earlier.

    FYI... that error occured in here:

    Code
    if obj.StreamName <> '' then //V5.17.3
                begin
                  RTFDataCollection.RequestHTTPImage(Self, FLoadPath, obj.StreamName, txtobj);
                // see: procedure TWPRTFReader.LoadLinkedImage
                  txtobj.Source := obj.StreamName;
                end;