Full implementation - shows how to work with sections

<< Click to Display Table of Contents >>

Navigation:  Programming > Sections >

Full implementation - shows how to work with sections

DELPHI CODE

 

procedure TWPALL.AppendClick(Sender: TObject);

  procedure AppendText(Source : TWPRTFDataCollection);

  var sectionprops : TWPRTFSectionProps ;

      i   : Integer;

      textblock : TWPRTFDataBlock;

  begin

    // Create a new Page if required

    if WPAll.IsEmpty then

         WPAll.CheckHasBody

    else WPAll.InputString(#12);

    // Create new section properties

    sectionprops := WPALL.HeaderFooter.AddSectionProps;

    // Assign the default page size

    sectionprops.Assign(Source.Header);

    sectionprops.Select := [wpsec_PageSize,wpsec_Margins];

    // Copy all header + footer into certain section

    for i:=0 to Source.Count-1 do

      if Source[i].Kind in [wpHeader, wpFooter] then

      begin

        textblock := WPALL.HeaderFooter.Append(

          Source[i].Kind,

          Source[i].Range,

          Source[i].Name);

        textblock.UsedForSectionID := sectionprops.SectionID;

        textblock.RtfText.Assign(Source[i].RTFText);

      end;

    // The current paragraph starts this section

    WPAll.ActiveParagraph.SectionID := sectionprops.SectionID;

    include(WPAll.ActiveParagraph.prop,paprNewSection);

    // Copy the text as part of a certain section

    WPAll.CPPosition := MaxInt;

    WPAll.SelectionAsString := Source.AsANSIString('WPTOOLS');

  end;

begin

 WPAll.Clear;

 AppendText(WP1.HeaderFooter);

 AppendText(WP2.HeaderFooter);

 AppendText(WP3.HeaderFooter);

end;

 

C++BUILDER Example:

This code appends the text from a different editor to "WPRichText1" as a new section

 

void __fastcall TWPALL::AppendNewSection(TWPRTFDataCollection * Source)

{

TWPRTFSectionProps * sectionprops;

TWPRTFDataBlock * textblock ;

int i;

 

// Create a new Page if required

if (this->WPRichText1->IsEmpty())

this->WPRichText1->CheckHasBody();

else this->WPRichText1->InputString("\f",0);

 

// Create new section properties

sectionprops = this->WPRichText1->HeaderFooter->AddSectionProps();

 

// Assign the default page size

sectionprops->Assign(Source->Header);

 

//sectionprops->Select = [wpsec_PageSize,wpsec_Margins];

sectionprops->Select << wpsec_PageSize << wpsec_Margins ;

 

// Copy all header + footer into certain section

for (i=0; i < Source->Count; i++ )

{

TWPRTFDataBlock * src = Source->Items[i] ;

if ( src->Kind == wpHeader || src->Kind == wpFooter )

  {

  textblock = this->WPRichText1->HeaderFooter->Append(

  Source->Items[i]->Kind ,

  Source->Items[i]->Range ,

  Source->Items[i]->Name );

  textblock->UsedForSectionID = sectionprops->SectionID;

  textblock->RtfText->Assign(Source->Items[i]->RtfText);

  }

}//for()  

 

// The current paragraph starts this section

this->WPRichText1->ActiveParagraph->SectionID = sectionprops->SectionID;

 

//include(WPAll->ActiveParagraph->prop,paprNewSection);

this->WPRichText1->ActiveParagraph->prop << paprNewSection ;

 

// Copy the text as part of a certain section

this->WPRichText1->CPPosition = MaxInt;

this->WPRichText1->SelectionAsString = Source->AsANSIString("WPTOOLS");

}