<< Click to Display Table of Contents >> Navigation: Programming > Create text under program control > Paragraphs > TParagraph API > AppendParCopy |
If you need a low level routine to copy one paragraph and all the included paragraphs
(this can be table rows or table cells) to the destination editor use:
var par : TParagraph;
begin
// Get the reference to current paragraph
par := WPRichText1.ActiveParagraph;
// Append it to the active RTFDataBlock
DestWP.ActiveText.AppendParCopy(par);
// This moves to the next paragraph! Useful in a loop!
WPRichText1.ActiveParagraph := par;
// Format is required sometimes later
DestWP.DelayedReformat;
end;
For better understanding here the source of the AppendParCopy method:
function TWPRTFDataBlock.AppendParCopy(var SourcePar: TParagraph; SkipObjects: TWPTextObjTypes = []): TParagraph;
var toPar : TParagraph;
begin
if SourcePar = nil then Result := nil else
begin
Result := SourcePar.CreateCopy(Self, SkipObjects);
if Result.ParagraphType = wpIsTableRow then
begin
if Empty then
toPar := CreateTable(nil)
else begin
toPar := LastPar;
if toPar.ParagraphType <> wpIsTable then
toPar := CreateTable(nil);
end;
toPar.AppendChild(Result);
end else
AppendPar(Result);
SourcePar := SourcePar.NextPar;
end;
end;
You can see from this code that this routine tries to add new table rows to a table object which already exists in the text. So instead of moving the complete table you can also copy only selected rows. Since the result value of the AppendParCopy function is the new paragraph you can also do some pro-processing, for example apply certain attributes.
You can also use the SET parameter SkipObjects to leave out certain object types, such as [wpobjMergeField] to ignore mail merge fields (the contained text will be copied of course).