Function TWPCustomRtfEdit.CodeListTags(Code:TWPTextObjType; AName:string; GlobalSearch:Boolean) : TWPTextObjList
Unit: WPCTRMemo
Class: WPCTRMemo.TWPCustomRtfEdit
Parameters
-
Code:TWPTextObjType AName:string GlobalSearch:Boolean
Returns
The type of the result value is TWPTextObjList.
Description
This function creates a TWPTextObjList and fills it with all objects which have a certain type. InternallyThis functions fills a list with TTextObj instances with the given type (Code) and name (if >'')
This sample code renames all bookmarks in the document:
objlist := WPRichText1.CodeListTags(wpobjBookmark, '*ALL*', true);
for i:=0 to objlist.Count-1 do
if objlist.Closing[i]<>nil then
begin
objlist[i].Name := objlist[i].Name + '_changed';
objlist.Closing[i].Name := objlist[i].Name;
end;
objlist.Free;
Alternatively the loop
for i:=0 to objlist.Count-1 do
objlist.Names[i] := objlist.Names[i] + '_changed';
can be used.
This look find all objects with type = "wpobjCustom" and makes them a merge field. It can also regenerate the name:
var objlist : TWPTextObjList;
i : Integer;
s : String;
begin
objlist := WPRichText1.CodeListTags(wpobjCustom);
for I := 0 to objlist.Count-1 do
if objlist[i].EndTag<>nil then
begin
objlist[i].ObjType := wpobjMergeField;
objlist[i].EndTag.ObjType := wpobjMergeField;
if objlist[i].Name='' then
begin
objlist[i].Name := Copy(s,1,30); // Name = 30 chars of the embedded text
end;
end;
WPRichText1.ReformatAll(true,true);
end;