testgdbm2.pp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt, member of
  4. the Free Pascal development team
  5. Test strings interface to gdbm library
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. program testgdbm2;
  13. {$mode objfpc}
  14. {$h+}
  15. uses sysutils,gdbm;
  16. Var
  17. dbf : pgdbm_file;
  18. A,B : String;
  19. i : longint;
  20. begin
  21. dbf:=gdbm_open('test.dat',512,GDBM_NEWDB,432,nil);
  22. If dbf=Nil then
  23. Writeln('Error when creating database');
  24. for I:=1 to 10 do
  25. begin
  26. A:=Format('data for string %d',[i]);
  27. B:=Format('string %d',[i]);
  28. if not gdbm_store(dbf,B,A,gdbm_insert) then
  29. Writeln('Error inserting data')
  30. else
  31. Writeln('Inserted string ',i)
  32. end;
  33. gdbm_firstkey(dbf,B);
  34. I:=0;
  35. While B<>'' do
  36. begin
  37. inc(i);
  38. A:=gdbm_fetch(dbf,B);
  39. writeln('Data for key ',i,' (',B,') : ',A);
  40. B:=gdbm_nextkey(dbf,B);
  41. end;
  42. gdbm_close(dbf);
  43. end.