TDARemoteCommand

Overview

The TDARemoteCommand visual component allows to execute commands (stored procedures or SQL statements) from the Schema published by custom service.

By default, the standard TDataAbstractService class is configured to prevent the execution of arbitrary commands from the client, as this poses a possible security risk, depending on what kind of commands are defined in the schema.

To enable the execution of commands from the client, set the AllowExecuteCommands property of your TDataAbstractService to true and ensure that all published Commands in your schema are safe for execution. You also need to have proper authentication methods in place to prevent anonymous users from making malicious calls.

As an example, imagine the following scenario: In the Schema Modeler of your custom DA application, you have defined the remote data table Table1 and the command DeleteRow, which should delete the row with the specified ID from Table1.

procedure DeleteRowFromTable1(aID:integer);
var
  RemoteCommand:TDARemoteCommand;
begin
  try
    RemoteCommand:=TDARemoteCommand.Create(nil);
    RemoteCommand.RemoteService:=ClientDataModule.RemoteService;
    RemoteCommand.Execute('DeleteRow',['ID'],[aID]);
  finally
    FreeAndNil(RemoteCommand);
  end;
end;

In this code example, the RemoteCommand object hooks with the remote service, which contains the list of available commands, executes the command DeleteRow with the specified row ID.

The next example expands the scenario. If there are exceptions while deleting the command, error code is returned, if no exeptions are encountered (and 0 is returned):

function DeleteRowFromTable2(aID:integer):integer;
var
  RemoteCommand:TDARemoteCommand;
  lArray:DataParameterArray;
  ec:TRORemoteCommandRequest;
begin
  try
    RemoteCommand:=TDARemoteCommand.Create(nil);
    RemoteCommand.RemoteService:=ClientDataModule.RemoteService;
    ec := RemoteCommand.ExecuteCall;
    ec.MethodName := 'ExecuteCommandEx';
    ec.RefreshParams();
    ec.OutgoingParametersParameter := 'aInputParameters';
    ec.IncomingParametersParameter := 'aOutputParameters';
    RemoteCommand.Execute('DeleteRow',['ID'],[aID]);
    lArray := DataParameterArray(ec.Params.FindParam(ec.IncomingParametersParameter).AsComplexType);
    Result := DataParameter(lArray.Search('Name', 'ErrorCode')).Value;
  finally
    FreeAndNil(RemoteCommand);
  end;
end;

In this code example, the RemoteCommand object also returns the specified error code.

Location


 

constructor Create  override

Standard component constructor

constructor Create(aOwner: TComponent)

Parameters:

  • aOwner: Owner

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

Execute (string): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given name and returns the number of affected rows.

function Execute(aCommandName: string): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.

Execute (string, DataParameterArray): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given name and input parameters and returns the number of affected rows.

function Execute(aCommandName: string; aInputParameters: DataParameterArray): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aInputParameters: Specified array with input parameters.

Execute (string, DataParameterArray, DataParameterArray): Integer  override

Executes the command with the given name and input parameters and returns the number of affected rows and output parameters.

function Execute(aCommandName: string; aInputParameters: DataParameterArray; out aOutputParameters: DataParameterArray): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aInputParameters: Specified array with input parameters.
  • aOutputParameters: Specified array with output parameters.

Execute (string, array of string, array of Variant): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given name and input parameters and returns the number of affected rows.

function Execute(aCommandName: string; aParamNames: array of string; aParamValues: array of Variant): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aParamNames: Specified array with input parameter names that will be encoded to UTF8 format.
  • aParamValues: specified array with input parameter values.

Execute (string, array of Variant): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given input parameters and returns the number of affected rows.

function Execute(aCommandName: string; aParamValues: array of Variant): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aParamValues: specified array with input parameter values.

ExecuteCall

Represents the Dynamic Request that will be used to invoke the Command on the server. By default, it will be mapped to the ExecuteCommand call as defined in the IDataAbstractService implemented by the standard Data Abstract 4.0 servers. When using a custom server interface, you can change its sub-properties to control how the data update call is made.

property ExecuteCall: TRORemoteCommandRequest read write

Notification  protected override

Forwards notification messages to all owned components.

procedure Notification(AComponent: TComponent; Operation: TOperation)

Parameters:

  • AComponent: component
  • Operation: operation

RemoteService

References the TRORemoteService component that defines the service to call for executing the command.

property RemoteService: TRORemoteService read write

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure ROFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure RORemoveFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

SendRemoveNotification  protected    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure SendRemoveNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

 

ExecuteCall

Represents the Dynamic Request that will be used to invoke the Command on the server. By default, it will be mapped to the ExecuteCommand call as defined in the IDataAbstractService implemented by the standard Data Abstract 4.0 servers. When using a custom server interface, you can change its sub-properties to control how the data update call is made.

property ExecuteCall: TRORemoteCommandRequest read write

RemoteService

References the TRORemoteService component that defines the service to call for executing the command.

property RemoteService: TRORemoteService read write

 

constructor Create  override

Standard component constructor

constructor Create(aOwner: TComponent)

Parameters:

  • aOwner: Owner

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

Execute (string): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given name and returns the number of affected rows.

function Execute(aCommandName: string): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.

Execute (string, DataParameterArray): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given name and input parameters and returns the number of affected rows.

function Execute(aCommandName: string; aInputParameters: DataParameterArray): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aInputParameters: Specified array with input parameters.

Execute (string, DataParameterArray, DataParameterArray): Integer  override

Executes the command with the given name and input parameters and returns the number of affected rows and output parameters.

function Execute(aCommandName: string; aInputParameters: DataParameterArray; out aOutputParameters: DataParameterArray): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aInputParameters: Specified array with input parameters.
  • aOutputParameters: Specified array with output parameters.

Execute (string, array of string, array of Variant): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given name and input parameters and returns the number of affected rows.

function Execute(aCommandName: string; aParamNames: array of string; aParamValues: array of Variant): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aParamNames: Specified array with input parameter names that will be encoded to UTF8 format.
  • aParamValues: specified array with input parameter values.

Execute (string, array of Variant): Integer  overload    (declared in TDABaseCommand)

Executes the command with the given input parameters and returns the number of affected rows.

function Execute(aCommandName: string; aParamValues: array of Variant): Integer

Parameters:

  • aCommandName: Name of the command that is declared in the schema.
  • aParamValues: specified array with input parameter values.

Notification  protected override

Forwards notification messages to all owned components.

procedure Notification(AComponent: TComponent; Operation: TOperation)

Parameters:

  • AComponent: component
  • Operation: operation

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure ROFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure RORemoveFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

SendRemoveNotification  protected    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure SendRemoveNotification(aComponent: TComponent)

Parameters:

  • aComponent: component