vcl-dxai-2af68592.md
The procedural type for AI command list population events.
TdxOnGetAICommands = procedure(Sender: TObject; const AAICommands: TdxAICommandList) of object;
| Name | Type | Description |
|---|---|---|
| Sender | TObject |
Provides access to the control that raised the AI command list population event. You need to cast this parameter value to the corresponding terminal control class to access public API members.
Tip
Call the Sender.ClassType function or use other RTTI functionality to identify the actual control class.
| | AAICommands | TdxAICommandList |
Provides access to the pre-populated list of AI-powered end-user commands.
Call AAICommands.Add or AAICommands.Remove procedures to add or remove individual commands. To enable or disable UI elements associated with corresponding commands, use the AAICommands.Available property.
Refer to the TdxAICommandList class description for detailed information on all available options (including the full list of predefined AI command IDs).
|
An AI command list population event occurs every time a supported control displays UI elements mapped to AI-powered end-user commands. You can handle these events to manage the list of available AI-powered commands and modify their status depending on specific conditions in your application.
The following code example moves Explain and Proofread commands to the second and third positions in a context menu, respectively:
uses
dxRichEdit.Control, // Declares TdxRichEditControl
dxAI; // Declares AI-specific types
// ...
procedure TMyForm.dxRichEditControl1GetAICommands(Sender: TObject;
const AAICommands: TdxAICommandList);
var
ACommandIndex: Integer;
begin
ACommandIndex := AAICommands.IndexOf(TdxAICommandIDs.Explain);
AAICommands.Move(ACommandIndex, 1); // Moves "Explain" to the second position (after "Expand")
ACommandIndex := AAICommands.IndexOf(TdxAICommandIDs.Proofread);
AAICommands.Move(ACommandIndex, 2); // Moves "Proofread" to the third position (after "Explain")
end;
#include "dxRichEdit.Control.hpp" // Declares TdxRichEditControl
#include "dxAI.hpp" // Declares AI-specific types
// ...
void __fastcall TMyForm::dxRichEditControl1GetAICommands(TObject *Sender,
const TdxAICommandList *AAICommands)
{
int ACommandIndex = AAICommands->IndexOf(TdxAICommandIDs::Explain);
AAICommands->Move(ACommandIndex, 1); // Moves "Explain" to the second position (after "Expand")
ACommandIndex = AAICommands->IndexOf(TdxAICommandIDs::Proofread);
AAICommands->Move(ACommandIndex, 2); // Moves "Proofread" to the third position" (after "Explain")
}
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
The following events reference the TdxOnGetAICommands procedural type:
TcxCustomTextEditProperties.OnGetAICommandsAllows you to modify the list of AI-powered commands available in the editor.TdxRichEditControlBase.OnGetAICommandsAllows you to modify the list of AI-powered commands available in the Rich Edit control. See Also