a) How to build a list of all hyperlinks in a document:
You can use the 'Loop..' procedure of the RTFDataCollection for this. It expects a a parameter object (any) and the callback. The cllback can be either a global or a object (TForm) procedure:
procedure TForm1.LoopAllObjectCall( RTFData: TWPRTFDataCollection; RTFDataBlock: TWPRTFDataBlock; par: TParagraph; obj: TWPTextObj; param: TObject);begin if (obj.ObjType=wpobjHyperlink) and (wpobjIsOpening in obj.Mode) then begin (param as TStringList).Add( obj.Source ); end;end;procedure TForm1.Button8Click(Sender: TObject);var list_of_hyperlinks : TStringList;begin list_of_hyperlinks := TStringList.Create; try WPRichText1.Memo.RTFData.LoopAllObj( list_of_hyperlinks, LoopAllObjectCall); finally ShowMessage(list_of_hyperlinks.Text); list_of_hyperlinks.Free; end;end;
b) To loop all paragraphs I suggest to simply use
var par : TParagraph;
par := WPRichText1.FirstPar;
while par<>nil do
begin
par := par.Next;
end;
This loops through the current text, not in header and footer. If you need that, too start with
WPRichText1.Memo.RTFData.FirstPar and use
par.globalnext instead of par.next
c) To loop through the text you can also use a different Loop procedure, too: LoopAllPar
d) The TextCursor also has a procedure for callbacks: CallForSelectedText. Obviously this helps to check out the text which is selected. It has the ability to only report uinque charattr ids.
Julian