Back to Devexpress

TdxRichEditControlBase.OnGetAICommands Event

vcl-dxrichedit-dot-control-dot-core-dot-tdxricheditcontrolbase.md

latest6.5 KB
Original Source

TdxRichEditControlBase.OnGetAICommands Event

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

Declaration

delphi
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.

AI-powered Command Implementation

In v25.2, 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:

SenderProvides access to the Rich Edit control that raised the OnGetAICommands event.AAICommandsProvides 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:

delphi
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;
cpp
#include "dxRichEdit.Control.hpp" // Declares TdxRichEditControl
#include "dxAI.hpp" // Declares AI-specific types
// ...

void __fastcall TMyForm::dxRichEditControl1GetAICommands(TObject *Sender,
  const TdxAICommandList *AAICommands)
{
  if((dynamic_cast<TdxRichEditControl*>(Sender)->Document->Selections->Count == 0) ||
    ((dynamic_cast<TdxRichEditControl*>(Sender)->Document->Selection->Length == 0)))
      AAICommands->Clear();
}

Disable Individual AI-powered Commands

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

delphi
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;
cpp
#include "dxRichEdit.Control.hpp" // Declares TdxRichEditControl
#include "dxAI.hpp" // Declares AI-specific types
#include "dxAI.Commands.Consts;" // Declares AI command identifiers
// ...

void __fastcall TMyForm::dxRichEditControl1GetAICommands(TObject *Sender,
  const TdxAICommandList *AAICommands)
{
  AAICommands->Available[TdxAICommandIDs::Expand] = false;
  AAICommands->Available[TdxAICommandIDs::Shorten] = false;
  AAICommands->Available[TdxAICommandIDs::Summarize] = false;
}

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

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:

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

TcxCustomTextEditProperties.OnGetAICommands Event

TdxRichEditControlBase Class

TdxRichEditControlBase Members

dxRichEdit.Control.Core Unit