crudclient.lpr 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. program crudclient;
  26. {$MODE DELPHI}
  27. {$WARN 4046 OFF}
  28. {$WARN 5062 OFF}
  29. uses
  30. DB,
  31. Client;
  32. const
  33. URL_SERVER = 'http://localhost:8080';
  34. procedure ListAllPersons;
  35. begin
  36. with ListPersons(URL_SERVER) do
  37. try
  38. while not EOF do
  39. begin
  40. WriteLn(FieldByName('id').AsInteger, ' ', FieldByName('name').AsString);
  41. Next;
  42. end;
  43. finally
  44. Free;
  45. end;
  46. end;
  47. procedure AddRandomPersons;
  48. var
  49. VDataSet: TDataSet;
  50. VField: TField;
  51. begin
  52. VDataSet := CreatePersonsDataSet;
  53. VField := VDataSet.FieldByName('name');
  54. VDataSet.Append;
  55. VField.AsString := 'Person ' + NewGuid;
  56. VDataSet.Append;
  57. VField.AsString := 'Person ' + NewGuid;
  58. SavePersons(URL_SERVER, VDataSet);
  59. end;
  60. begin
  61. Randomize;
  62. ListAllPersons;
  63. AddRandomPersons;
  64. ListAllPersons;
  65. end.