unit uTestHTTPClient;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, uPS_HTTPClient_Main, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
  FireDAC.Phys, FireDAC.VCLUI.Wait, Data.DB, FireDAC.Comp.Client, Vcl.StdCtrls,

  //myUnits
  uDBConnection, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
  FireDAC.DApt, Vcl.Grids, Vcl.DBGrids, FireDAC.Comp.DataSet, Vcl.Menus

  ;

type
  TfTestHTTPClient = class(TForm)
    PS_HTTPClient1: TPS_HTTPClient;
    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);
    procedure FDTable1CalcFields(DataSet: TDataSet);
    procedure bTestClick(Sender: TObject);
  private
    { Private declarations }
//   PS_HTTPClient1:TPS_HTTPClient;

   FDBConnection: TDBConnection;



  public
    { Public declarations }

   constructor Create(AOwner: TComponent); override;

  end;

var
  fTestHTTPClient: TfTestHTTPClient;

implementation

{$R *.dfm}




procedure TfTestHTTPClient.bTestClick(Sender: TObject);
begin
//

if FDBConnection.Connect then ShowMessage('Connected');

end;

constructor TfTestHTTPClient.Create(AOwner: TComponent);
begin
  inherited;
//

FDBConnection:=TDBConnection.Create(Self);
FDBConnection.Connect;

end;

procedure TfTestHTTPClient.FDTable1CalcFields(DataSet: TDataSet);
begin

//FDTable1SomeCalcField.Value:='123';

//DataSet.FieldByName('FDTable1SomeCalcField').AsString:='123';

end;

procedure TfTestHTTPClient.FormCreate(Sender: TObject);

var oParams:TStrings;

begin


ReportMemoryLeaksOnShutdown:=true; // small memory leaks in code



// defining HTTP_ConnectionParams and Server To Request

    with PS_HTTPClient1.visualFrame do begin


      with HTTP_ConnectionParams do begin

      Protocol:='http';
      Host:='localhost';//'40.85.142.196';//'192.168.1.102';//'localhost';
      Port:='40000';
      IdUser:='1'; // << Critical important to use ID that are in DataBase coffeetest.users
      User:='SomeUser';

      end;


      DefineServerToRequest;

      // Database Settings




      FDConnection:=(FDBConnection.FDConnection);
      FDTable.Connection:=FDConnection;

      //DataBaseUnit.FDConnectionExternal:=FDBConnection.FDConnection;
      //DataBaseUnit.FDConnection:=FDBConnection.FDConnection;

      DataBaseUnit.ConnectQueriesAndFDTable;


//
      //DataSource.DataSet:=DataBaseUnit.FDTable;

         DataBaseUnit.AdjustDBGrid;
//         FDTable.Fields.Clear; // fix for bug 'type mismatch'

         //      DataBaseUnit.FDTableCalcFields(DataBaseUnit.FDTable);
//      FDTable.Close();
//      FDTable.Open();



      InitialUpdate;


    end;



end;

procedure TfTestHTTPClient.FormDestroy(Sender: TObject);
begin
//PS_HTTPClient1.Free; // << must be to avoid memory leaks
end;








end.
