Friday, February 18, 2005

Delphi: Change rich edit format without changing selection

If you are using Microsoft's Rich Edit control v2+ then you can change a paragraph's format without selecting that paragraph if you use the ITextDocument COM interface.


var
rich_edit_ole: IRichEditOle;
doc_dispatch: IDispatch;
doc, range: Variant;
begin
if RichEdit_GetOleInterface(rich_edit.Handle, rich_edit_ole) then begin
OleCheck(rich_edit_ole.QueryInterface(IDispatch, doc_dispatch));
// Use Variants because we do not have Delphi declarations for
// the ITextDocument and ITextRange interfaces.
doc := doc_dispatch;
range := doc.Range(start_char, end_char);
range.SpaceAfter := 12;
end;

Note that you are not using Rich Edit v2+ if you use Delphi's inbuilt TRichEdit. TRichEdit specifically requests v1, which does not support the Text Object Model (TOM). I use Alexander Obukhov's TRichEdit98.

0 Comments:

Post a Comment

<< Home