Skip to main content
All docs
V25.1
  • TdxRichEditControlBase.OnGetAICommands Event

    Allows you to modify the list of AI-powered commands available in the Rich Edit control.

    Declaration

    property OnGetAICommands: TdxOnGetAICommands read; write;

    Remarks

    Handle the OnGetAICommands event to modify the list of AI-powered commands available in the Rich Edit control and change the state of individual commands depending on specific conditions in your application. All required dependencies (dxAI and dxAI.Commands.Text units) are added automatically to the project if you implement an OnGetAICommands event handler.

    VCL Rich Edit: AI-Powered Commands

    AI-Powered Command Implementation

    In v25.1, we ship no AI provider interaction APIs for DevExpress VCL controls[1]. Until Embarcadero ships official AI-related SDK libraries, VCL developers can plug in third-party libraries or leverage their own implementation to support different AI providers. We also published a GitHub example with a custom TdxAIChatClient implementation for a popular open-source AI library.

    Event Occurrence

    The OnGetAICommands event occurs every time the context menu is about to appear in the Rich Edit control.

    Note

    The OnGetAICommands event can occur only if an AI service provider is registered and AI user commands are initialized.

    Event Parameters

    The following parameters are available within an OnGetAICommands event handler:

    Sender
    Provides access to the Rich Edit control that raised the OnGetAICommands event.
    AAICommands
    Provides access to a pre-populated collection of AI-powered commands available in the Rich Edit control. Use this parameter to add, remove, rearrange, disable, or enable individual end-user AI commands.

    Refer to the TdxOnGetAICommands procedural type description for detailed information on all parameters accessible within an OnGetAICommands event handler.

    Code Examples

    Hide AI-Powered Commands

    The following code example hides all AI-powered commands (removes the AI Assistant item) when no content is selected in the document:

    uses
      dxRichEdit.Control,  // Declares TdxRichEditControl
      dxAI;  // Declares AI-specific types
    // ...
    
    procedure TMyForm.dxRichEditControl1GetAICommands(Sender: TObject;
      const AAICommands: TdxAICommandList);
    begin
      if ((Sender as TdxRichEditControl).Document.Selections.Count = 0) or
         ((Sender as TdxRichEditControl).Document.Selection.Length = 0) then
           AAICommands.Clear;
    end;
    

    VCL Rich Edit: The Context Menu Without AI-Powered Commands

    Disable Individual AI-Powered Commands

    The following code example disables Expand, Shorten and Summarize commands in the context menu:

    uses
      dxRichEdit.Control,  // Declares TdxRichEditControl
      dxAI,  // Declares AI-specific types
      dxAI.Commands.Consts;  // Declares AI command identifiers
    // ...
    
    procedure TMyForm.dxRichEditControl1GetAICommands(Sender: TObject;
      const AAICommands: TdxAICommandList);
    begin
      AAICommands.Available[TdxAICommandIDs.Expand] := False;
      AAICommands.Available[TdxAICommandIDs.Shorten] := False;
      AAICommands.Available[TdxAICommandIDs.Summarize] := False;
    end;
    

    VCL Rich Edit: Individual Disabled AI-Powered Commands

    To see AI-powered commands in action, run the Word Processing RTF demo in the VCL Demo Center installed with compiled VCL DevExpress demos.

    VCL Rich Edit: AI-Powered Commands

    Select a text range, right-click within the control area, and expand the AI Assistant item to select the required command. The demo displays the result in a separate modal dialog:

    VCL Rich Edit: A Translation Result Example

    The Word Processing RTF demo uses our Azure OpenAI Service deployment implemented as the TdxAIAzureChatClient class declared in the dxAI.ChatClient.Azure.pas unit shipped with demo source code.

    Download: Compiled VCL Demos

    Tip

    You can find full source code for the installed Rich Edit control demo in the following folder:

    %PUBLIC%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressRichEditControl

    Footnotes
    1. Except for web-based ExpressReports that support the same AI-powered extensions available for DevExpress Web Reports. You can enable these extensions in the Project Settings dialog.

    See Also