vcl-dxrichedit-dot-control-dot-core-dot-tdxricheditcontrolbase.md
Allows you to modify the list of AI-powered commands available in the Rich Edit control.
property OnGetAICommands: TdxOnGetAICommands read; write;
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.
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.
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.
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.
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;
#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();
}
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;
#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:
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
See Also
TcxCustomTextEditProperties.OnGetAICommands Event