Skip to main content

IdxRichEditSubDocument.BeginUpdateCharacters(Integer,Integer) Method

Starts to update character properties of the document range defined by its length and position in a document.

Declaration

function BeginUpdateCharacters(AStart: Integer; ALength: Integer): IdxRichEditCharacterProperties; overload;

Parameters

Name Type Description
AStart Integer

The target position in a document. You can call a document position‘s ToInt function to obtain the required value.

ALength Integer

The length of the target document range.

Returns

Type Description
IdxRichEditCharacterProperties

The target document range’s character properties.

Remarks

BeginUpdateCharacters and EndUpdateCharacters are the key methods in the text editing API. A BeginUpdateCharacters method call obtains character properties of the target document range. The EndUpdateCharacters procedure accepts these character settings and applies the changes made between BeginUpdateCharacters and EndUpdateCharacters calls.

Example

The following code example applies the Bold font attribute to all selected document ranges and changes their font and background colors:

var
  ADocument: IdxRichEditDocument;
  ARange: IdxRichEditDocumentRange;
  ACharacterProperties: IdxRichEditCharacterProperties;
  I: Integer;
begin
  ADocument := dxRichEditControl1.Document;
  ADocument.BeginUpdate;  // Locks the document updates and starts recording an edit user action
  for I := 0 to ADocument.Selections.Count - 1 do  // Iterates through all selected document ranges
    begin
      // Obtains character properties of the current selected document range
      ARange := ADocument.Selections.Self[I];
      ACharacterProperties := ADocument.BeginUpdateCharacters(ARange.Start.ToInt, ARange.Length);
      ACharacterProperties.BackColor := TdxAlphaColors.Blue;
      ACharacterProperties.ForeColor := TdxAlphaColors.White;
      ACharacterProperties.Bold := True;
      ADocument.EndUpdateCharacters(ACharacterProperties);  // Applies the changes to the range
    end;
  ADocument.EndUpdate;  // Applies all pending changes to the document and unlocks document updates
end;

Selected Document Ranges Highlight Example

Note

Add the dxCoreGraphics unit to your project’s uses clause to be able to use the TdxAlphaColors type.

See Also