//
// Created by the DataSnap proxy generator.
// 07.09.2015 23:21:32
//

unit ClientMethods1;

interface

uses System.JSON, Data.DBXCommon, Data.DBXClient, Data.DBXDataSnap, Data.DBXJSON, Datasnap.DSProxy, System.Classes, System.SysUtils, Data.DB, Data.SqlExpr, Data.DBXDBReaders, Data.DBXCDSReaders, Data.DBXJSONReflect;

type
  TServerMethods1Client = class(TDSAdminClient)
  private
    FDataSetProvider1GetTableNameCommand: TDBXCommand;
    FDSServerModuleCreateCommand: TDBXCommand;
    FDataSetProvider1BeforeGetRecordsCommand: TDBXCommand;
    FDataSetProvider1AfterGetRecordsCommand: TDBXCommand;
    FEchoStringCommand: TDBXCommand;
    FReverseStringCommand: TDBXCommand;
    FGetPictureCommand: TDBXCommand;
    FGetStringCommand: TDBXCommand;
  public
    constructor Create(ADBXConnection: TDBXConnection); overload;
    constructor Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean); overload;
    destructor Destroy; override;
    procedure DataSetProvider1GetTableName(Sender: TObject; DataSet: TDataSet; var TableName: string);
    procedure DSServerModuleCreate(Sender: TObject);
    procedure DataSetProvider1BeforeGetRecords(Sender: TObject; var OwnerData: OleVariant);
    procedure DataSetProvider1AfterGetRecords(Sender: TObject; var OwnerData: OleVariant);
    function EchoString(Value: string): string;
    function ReverseString(Value: string): string;
    procedure GetPicture(filename: TMemoryStream);
    procedure GetString(s: WideString);
  end;

implementation

procedure TServerMethods1Client.DataSetProvider1GetTableName(Sender: TObject; DataSet: TDataSet; var TableName: string);
begin
  if FDataSetProvider1GetTableNameCommand = nil then
  begin
    FDataSetProvider1GetTableNameCommand := FDBXConnection.CreateCommand;
    FDataSetProvider1GetTableNameCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FDataSetProvider1GetTableNameCommand.Text := 'TServerMethods1.DataSetProvider1GetTableName';
    FDataSetProvider1GetTableNameCommand.Prepare;
  end;
  if not Assigned(Sender) then
    FDataSetProvider1GetTableNameCommand.Parameters[0].Value.SetNull
  else
  begin
    FMarshal := TDBXClientCommand(FDataSetProvider1GetTableNameCommand.Parameters[0].ConnectionHandler).GetJSONMarshaler;
    try
      FDataSetProvider1GetTableNameCommand.Parameters[0].Value.SetJSONValue(FMarshal.Marshal(Sender), True);
      if FInstanceOwner then
        Sender.Free
    finally
      FreeAndNil(FMarshal)
    end
    end;
  FDataSetProvider1GetTableNameCommand.Parameters[1].Value.SetDBXReader(TDBXDataSetReader.Create(DataSet, FInstanceOwner), True);
  FDataSetProvider1GetTableNameCommand.Parameters[2].Value.SetWideString(TableName);
  FDataSetProvider1GetTableNameCommand.ExecuteUpdate;
  TableName := FDataSetProvider1GetTableNameCommand.Parameters[2].Value.GetWideString;
end;

procedure TServerMethods1Client.DSServerModuleCreate(Sender: TObject);
begin
  if FDSServerModuleCreateCommand = nil then
  begin
    FDSServerModuleCreateCommand := FDBXConnection.CreateCommand;
    FDSServerModuleCreateCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FDSServerModuleCreateCommand.Text := 'TServerMethods1.DSServerModuleCreate';
    FDSServerModuleCreateCommand.Prepare;
  end;
  if not Assigned(Sender) then
    FDSServerModuleCreateCommand.Parameters[0].Value.SetNull
  else
  begin
    FMarshal := TDBXClientCommand(FDSServerModuleCreateCommand.Parameters[0].ConnectionHandler).GetJSONMarshaler;
    try
      FDSServerModuleCreateCommand.Parameters[0].Value.SetJSONValue(FMarshal.Marshal(Sender), True);
      if FInstanceOwner then
        Sender.Free
    finally
      FreeAndNil(FMarshal)
    end
    end;
  FDSServerModuleCreateCommand.ExecuteUpdate;
end;

procedure TServerMethods1Client.DataSetProvider1BeforeGetRecords(Sender: TObject; var OwnerData: OleVariant);
begin
  if FDataSetProvider1BeforeGetRecordsCommand = nil then
  begin
    FDataSetProvider1BeforeGetRecordsCommand := FDBXConnection.CreateCommand;
    FDataSetProvider1BeforeGetRecordsCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FDataSetProvider1BeforeGetRecordsCommand.Text := 'TServerMethods1.DataSetProvider1BeforeGetRecords';
    FDataSetProvider1BeforeGetRecordsCommand.Prepare;
  end;
  if not Assigned(Sender) then
    FDataSetProvider1BeforeGetRecordsCommand.Parameters[0].Value.SetNull
  else
  begin
    FMarshal := TDBXClientCommand(FDataSetProvider1BeforeGetRecordsCommand.Parameters[0].ConnectionHandler).GetJSONMarshaler;
    try
      FDataSetProvider1BeforeGetRecordsCommand.Parameters[0].Value.SetJSONValue(FMarshal.Marshal(Sender), True);
      if FInstanceOwner then
        Sender.Free
    finally
      FreeAndNil(FMarshal)
    end
    end;
  FDataSetProvider1BeforeGetRecordsCommand.Parameters[1].Value.AsVariant := OwnerData;
  FDataSetProvider1BeforeGetRecordsCommand.ExecuteUpdate;
  OwnerData := FDataSetProvider1BeforeGetRecordsCommand.Parameters[1].Value.AsVariant;
end;

procedure TServerMethods1Client.DataSetProvider1AfterGetRecords(Sender: TObject; var OwnerData: OleVariant);
begin
  if FDataSetProvider1AfterGetRecordsCommand = nil then
  begin
    FDataSetProvider1AfterGetRecordsCommand := FDBXConnection.CreateCommand;
    FDataSetProvider1AfterGetRecordsCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FDataSetProvider1AfterGetRecordsCommand.Text := 'TServerMethods1.DataSetProvider1AfterGetRecords';
    FDataSetProvider1AfterGetRecordsCommand.Prepare;
  end;
  if not Assigned(Sender) then
    FDataSetProvider1AfterGetRecordsCommand.Parameters[0].Value.SetNull
  else
  begin
    FMarshal := TDBXClientCommand(FDataSetProvider1AfterGetRecordsCommand.Parameters[0].ConnectionHandler).GetJSONMarshaler;
    try
      FDataSetProvider1AfterGetRecordsCommand.Parameters[0].Value.SetJSONValue(FMarshal.Marshal(Sender), True);
      if FInstanceOwner then
        Sender.Free
    finally
      FreeAndNil(FMarshal)
    end
    end;
  FDataSetProvider1AfterGetRecordsCommand.Parameters[1].Value.AsVariant := OwnerData;
  FDataSetProvider1AfterGetRecordsCommand.ExecuteUpdate;
  OwnerData := FDataSetProvider1AfterGetRecordsCommand.Parameters[1].Value.AsVariant;
end;

function TServerMethods1Client.EchoString(Value: string): string;
begin
  if FEchoStringCommand = nil then
  begin
    FEchoStringCommand := FDBXConnection.CreateCommand;
    FEchoStringCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FEchoStringCommand.Text := 'TServerMethods1.EchoString';
    FEchoStringCommand.Prepare;
  end;
  FEchoStringCommand.Parameters[0].Value.SetWideString(Value);
  FEchoStringCommand.ExecuteUpdate;
  Result := FEchoStringCommand.Parameters[1].Value.GetWideString;
end;

function TServerMethods1Client.ReverseString(Value: string): string;
begin
  if FReverseStringCommand = nil then
  begin
    FReverseStringCommand := FDBXConnection.CreateCommand;
    FReverseStringCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FReverseStringCommand.Text := 'TServerMethods1.ReverseString';
    FReverseStringCommand.Prepare;
  end;
  FReverseStringCommand.Parameters[0].Value.SetWideString(Value);
  FReverseStringCommand.ExecuteUpdate;
  Result := FReverseStringCommand.Parameters[1].Value.GetWideString;
end;

procedure TServerMethods1Client.GetPicture(filename: TMemoryStream);
begin
  if FGetPictureCommand = nil then
  begin
    FGetPictureCommand := FDBXConnection.CreateCommand;
    FGetPictureCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FGetPictureCommand.Text := 'TServerMethods1.GetPicture';
    FGetPictureCommand.Prepare;
  end;
  FGetPictureCommand.Parameters[0].Value.SetStream(filename, FInstanceOwner);
  FGetPictureCommand.ExecuteUpdate;
end;

procedure TServerMethods1Client.GetString(s: WideString);
begin
  if FGetStringCommand = nil then
  begin
    FGetStringCommand := FDBXConnection.CreateCommand;
    FGetStringCommand.CommandType := TDBXCommandTypes.DSServerMethod;
    FGetStringCommand.Text := 'TServerMethods1.GetString';
    FGetStringCommand.Prepare;
  end;
  FGetStringCommand.Parameters[0].Value.SetWideString(s);
  FGetStringCommand.ExecuteUpdate;
end;


constructor TServerMethods1Client.Create(ADBXConnection: TDBXConnection);
begin
  inherited Create(ADBXConnection);
end;


constructor TServerMethods1Client.Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean);
begin
  inherited Create(ADBXConnection, AInstanceOwner);
end;


destructor TServerMethods1Client.Destroy;
begin
  FDataSetProvider1GetTableNameCommand.DisposeOf;
  FDSServerModuleCreateCommand.DisposeOf;
  FDataSetProvider1BeforeGetRecordsCommand.DisposeOf;
  FDataSetProvider1AfterGetRecordsCommand.DisposeOf;
  FEchoStringCommand.DisposeOf;
  FReverseStringCommand.DisposeOf;
  FGetPictureCommand.DisposeOf;
  FGetStringCommand.DisposeOf;
  inherited;
end;

end.

