How to insert par at top after loading from file

  • I'm using the code bellow to insert a paragraph at the top of a
    document after loading an external file. The problem is that the
    text always appears at the end and not at the top of the document

    WPRichText1.Clear;
    WPRichText1.CheckHasBody;
    WPRichText1.DefaultIOFormat := 'HTML';
    WPRichText1.TextLoadFormat := 'HTML';
    WPRichText1.TextSaveFormat := 'HTML';
    WPRichText1.LoadFromFile( 'C:\test.html');

    WPRichText1.CPPosition :=0;
    par := WPRichText1.InsertPar;
    par.SetText('TO:');

  • I'd say you're pretty darn close. It looks like there's maybe a couple of lines missing. Perhaps try something like this in the area of your CPPosition := 0:

    Code
    with WPRichText1 do begin
       CPPosition := 0;
       par := FirstPar;           // <------ these are the two lines
       par := par.AppendNewPar;   // <------  you might try inserting
       // now, back to your code
       par.SetText('TO:');
    end;


    Note that I used WPRichText1.FirstPar, which works off of wpIsBody implicitly, rather than ActiveFirstPar, which works off of ActiveText, and could be wpIsBody, wpIsHeader, wpIsFooter, or whatever else ActiveText happens to be at that instant.

    No guarantees, but give it a shot! And, as always, I defer to Julian on this and all other matters..:)

    Regards,
    richard diamond