Need help with removing a line when a field is blank

  • In WPT4, we located and deleted lines if the line was blank due to a field being blank. I need to replicate this in 7, but am having a difficult time doing that. Here is the code in 4 (verify finds the position of the first char that is not in the substring after it, so first one that is not blank or <):

    AllRTFText.Finder.Wildcard := '*';

    AllRTFText.Finder.ToStart;

    AllRTFText.CPPosition := 0;

    NotDone := AllRTFText.Find('<',false);

    while NotDone do

    begin

    VIdx := verify(trim(AllRTFText.CPline),' <');

    if (VIdx = 0)

    or (AllRtfText.CPLine = #10)

    or (AllRTFText.CPline = #13)

    or (AllRTFText.CPline = #10 + #13) then

    AllRTFText.RtfText.DeleteLine;

    NotDone := AllRTFText.FindNext;

    end;

    • Offizieller Beitrag

    Well, WPTools 7 is way outdated and I recommend to get the new version 9.3.

    How do you define "fields"? Since you look for '<' these do not appear to be merge fields.

    If it were merge fields you can use CodeGetList to get all merge fields, detect of the obj.EmbeddedText is empty and call DeleteParagraph for the parent paragraph of the respected fields.

    The code above assumes that the text is in a string list. It is insetad in an XML like structure of paragraphs. With WPTools it is best, and one of the huge advantage of WPTools underlying technology, that you can loop through all the paragraphs and manipulate text and attributes on basis of the reference to a TParagraph object.

  • Thanks for the info. I am referring to merge fields and that code from 4 does work. I don't see a CodeGetList, but I do see a FieldGetList, which is what I have been trying to use. If I delete the parent paragraph, that will also delete other fields that are not blank. I am continuing to look at this, but to be clear, yes we are using merge fields. Sometimes the merge field ends up blank and is all by itself on a line. It is in those situations where we are trying to delete that line. We will move to the newest version, but am trying to get 4 to work with 7 for now.

    FYI, here is an example of the lines from 4:

    #9#9'Some Type of Number <ABC<1234567890'

    '<123 A.B.C. BLVD.'#$A

    '<'#$A

    This is the CPLine after I do a find on '<'. I delete the CPLine on the 3rd example.

    I have been able to do most of this by finding the fields, checking to see if cpline has a return only, if so, I blank out CPLine. That works for most, but I have some where I have a field to the right of other text in 2 different cells in a table where the text in the left column is blank also that gets deleted in WPT4 with TWPRichText.RtfText.DeleteLine. I will keep working on this, but if anything I said does not make sense, please enlighten me.

    Thanks again!

    3 Mal editiert, zuletzt von darren (20. September 2023 um 15:22)