unit MainForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  XData.Client, Sparkle.Http.Client, MyService;

type
  TForm6 = class(TForm)
    edUsername: TEdit;
    Label1: TLabel;
    edPassword: TEdit;
    Label2: TLabel;
    edA: TEdit;
    Label3: TLabel;
    edB: TEdit;
    Label4: TLabel;
    btSum: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btSumClick(Sender: TObject);
  private
    Client: TXDataClient;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

uses
  Sparkle.Utils;

{$R *.dfm}

procedure TForm6.btSumClick(Sender: TObject);
begin
  btSum.Caption := FloatToStr(
    Client.Service<IMyService>.Sum(StrToInt(edA.Text), StrToInt(edB.Text))
  );
end;

procedure TForm6.FormCreate(Sender: TObject);
begin
  Client := TXDataClient.Create;
  Client.Uri := 'http://localhost:2001/tms/xdata';
  Client.HttpClient.OnSendingRequest :=
    procedure(Req: THttpRequest)
    begin
      Req.Headers.SetValue('Authorization',
        TSparkleUtils.BasicAuthHeaderValue(edUserName.Text, edPassword.Text))
    end;
end;

procedure TForm6.FormDestroy(Sender: TObject);
begin
  Client.Free;
end;

end.
