DMClient.pas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. (* _ _
  2. * | |__ _ __ ___ ___ | | __
  3. * | '_ \| '__/ _ \ / _ \| |/ /
  4. * | |_) | | | (_) | (_) | <
  5. * |_.__/|_| \___/ \___/|_|\_\
  6. *
  7. * Microframework which helps to develop web Pascal applications.
  8. *
  9. * Copyright (c) 2012-2021 Silvio Clecio <[email protected]>
  10. *
  11. * Brook framework is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2.1 of the License, or (at your option) any later version.
  15. *
  16. * Brook framework is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with Brook framework; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *)
  25. unit DMClient;
  26. interface
  27. uses
  28. System.Classes,
  29. Data.DB,
  30. FireDAC.Stan.Intf,
  31. FireDAC.Stan.Option,
  32. FireDAC.Stan.Param,
  33. FireDAC.Stan.Error,
  34. FireDAC.DatS,
  35. FireDAC.Phys.Intf,
  36. FireDAC.DApt.Intf,
  37. FireDAC.Comp.DataSet,
  38. FireDAC.Comp.Client,
  39. FireDAC.Stan.StorageBin,
  40. System.Net.URLClient,
  41. System.Net.HttpClient,
  42. System.Net.HttpClientComponent;
  43. type
  44. TClient = class(TDataModule)
  45. FDMemTable: TFDMemTable;
  46. NetHTTPClient: TNetHTTPClient;
  47. FDStanStorageBinLink: TFDStanStorageBinLink;
  48. public
  49. procedure LoadPersons(const AURL: string);
  50. procedure SavePersons(const AURL: string);
  51. end;
  52. var
  53. Client: TClient;
  54. implementation
  55. {%CLASSGROUP 'FMX.Controls.TControl'}
  56. {$R *.dfm}
  57. { TClient }
  58. procedure TClient.LoadPersons(const AURL: string);
  59. begin
  60. FDMemTable.Close;
  61. FDMemTable.LoadFromStream(NetHTTPClient.Get(AURL).ContentStream, sfBinary);
  62. end;
  63. procedure TClient.SavePersons(const AURL: string);
  64. var
  65. VData: TStream;
  66. begin
  67. if FDMemTable.State in dsEditModes then
  68. FDMemTable.Post;
  69. VData := TBytesStream.Create;
  70. try
  71. FDMemTable.SaveToStream(VData, sfBinary);
  72. VData.Seek(0, TSeekOrigin.soBeginning);
  73. NetHTTPClient.Post(AURL, VData);
  74. finally
  75. VData.Free;
  76. end;
  77. end;
  78. end.