Back to Devexpress

IdxRichEditSubDocument.EndUpdateCharacters(IdxRichEditCharacterProperties) Method

vcl-dxrichedit-dot-nativeapi-dot-idxricheditsubdocument-dot-endupdatecharacters-x28-dxrichedit-dot-nativeapi-dot-idxricheditcharacterproperties-x29.md

latest3.9 KB
Original Source

IdxRichEditSubDocument.EndUpdateCharacters(IdxRichEditCharacterProperties) Method

Applies the character property changes initiated by a BeginUpdateCharacters function call.

Declaration

delphi
procedure EndUpdateCharacters(const AProperties: IdxRichEditCharacterProperties);

Parameters

NameTypeDescription
APropertiesIdxRichEditCharacterProperties

The character properties created by a BeginUpdateCharacters function call.

|

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.

Code Example: Apply Custom Formatting to Selected Text

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

delphi
var
  ADocument: IdxRichEditDocument;
  ACharacterProperties: IdxRichEditCharacterProperties;
  I: Integer;
begin
  ADocument := dxRichEditControl1.Document;
  ADocument.BeginUpdate; // Locks the document updates and starts recording an edit 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
      ACharacterProperties := ADocument.BeginUpdateCharacters(ADocument.Selections.Self[I]);
      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;
cpp
_di_IdxRichEditDocument ADocument;
  _di_IdxRichEditCharacterProperties ACharacterProperties;
  // ...
  ADocument = dxRichEditControl1->Document;
  ADocument->BeginUpdate(); // Locks the document updates and starts recording an edit action
  for(int i = 0; i < ADocument->Selections->Count; i++) // Iterates through all selected document ranges
  {
    // Obtains character properties of the current selected document range
    ACharacterProperties = ADocument->BeginUpdateCharacters(ADocument->Selections->Self[I]);
    ACharacterProperties->BackColor = TdxAlphaColors::Blue;
    ACharacterProperties->ForeColor = TdxAlphaColors::White;
    ACharacterProperties->Bold = true;
    ADocument->EndUpdateCharacters(ACharacterProperties); // Applies the changes
  }
  ADocument->EndUpdate(); // Applies all pending changes to the document and unlocks document updates

Note

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

See Also

IdxRichEditSubDocument Interface

IdxRichEditSubDocument Members

dxRichEdit.NativeApi Unit