<< Click to Display Table of Contents >> Navigation: Programming > Load & Save > Find text and replace by loaded text |
This code locates a token in the text and then calls LoadSelectionFromFile to replace it with loaded text.
WPRichTExt1.Finder.ToStart;
if WPRichTExt1.Finder.Next('{aToken}') then
begin
WPRichTExt1.Finder.SelectText;
WPRichTExt1.LoadSelectionFromFile('sometext.rtf');
end;
If you also need to apply the attributes used by the text token, you can use GetCharAttr(tsTrue) to lock in the attribute and apply that attribute later.
WPRichTExt1.Finder.ToStart;
if WPRichTExt1.Finder.Next('{aToken}') then
begin
WPRichTExt1.Finder.SelectText;
WPRichTExt1.GetCharAttr(tsTrue);
WPRichTExt1.LoadSelectionFromFile('sometext.rtf','',true);
WPRichTExt1.SelectedTextAttr.Assign(WPRichTExt1.WritingAttr);
WPRichTExt1.GetCharAttr(tsFalse);
end;