home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 January / Chip_1999-01_cd.bin / zkuste / delphi / QDB / ANIMALS.ZIP / ani_main.pas < prev    next >
Pascal/Delphi Source File  |  1998-06-28  |  4KB  |  120 lines

  1.  
  2. {*****************************************************************************}
  3. {                                                                             }
  4. {                            Animals Demo                                     }
  5. {                                                                             }
  6. {                     illustrating the use of the                             }
  7. {                                                                             }
  8. {            QDB v2.10 Visual Components for Delphi 1, 2, & 3                 }
  9. {                                                                             }
  10. {       Copyright (c) 1995, 1996, 1997, 1998, Robert R. Marsh, S.J.           }
  11. {             & the British Province of the Society of Jesus                  }
  12. {                                                                             }
  13. {                                                                             }
  14. {       You may use this demonstration application and modify it in           }
  15. {       whatever way you choose. You may not, however, sell it for            }
  16. {       profit unless the changes you have made are substantial (i.e.,        }
  17. {       more than 50% new code), in which case I'd appreciate                 }
  18. {       receiving a copy of your new work.                                    }
  19. {                                                                             }
  20. {       If you like Animals and find yourself using it please                 }
  21. {       consider making a donation to your favorite charity.                  }
  22. {                                                                             }
  23. {    Users of Animals must accept the following disclaimer of warranty:       }
  24. {                                                                             }
  25. {       Animals is supplied as is. The author disclaims all warranties,       }
  26. {       expressed or implied, including, without limitation, the              }
  27. {       warranties of merchantability and of fitness for any purpose.         }
  28. {       The author assumes no liability for damages, direct or                }
  29. {       consequential, which may result from the use of Animals.              }
  30. {                                                                             }
  31. {*****************************************************************************}
  32.  
  33. unit ani_main;
  34.  
  35. interface
  36.  
  37. uses
  38.   SysUtils, WinTypes, WinProcs, Graphics, Forms, Classes, StdCtrls, Buttons,
  39.   ExtCtrls, Controls, QDB;
  40.  
  41. type
  42.   Tani_form = class(TForm)
  43.     Panel1: TPanel;
  44.     Label1: TLabel;
  45.     BitBtn1: TBitBtn;
  46.     {these are the replacements for their DB counterparts}
  47.     Edit1: TEdit;
  48.     Edit2: TEdit;
  49.     Edit3: TEdit;
  50.     Edit4: TEdit;
  51.     Image1: TImage;
  52.     QDB1: TQDB;
  53.     QDBNavigator1: TQDBNavigator;
  54.     procedure FormCreate(Sender: TObject);
  55.     procedure QDB1Navigate(Sender: TObject);
  56.     procedure FormDestroy(Sender: TObject);
  57.   private
  58.   end;
  59.  
  60. var
  61.   ani_form: Tani_form;
  62.  
  63. implementation
  64.  
  65. {$R *.DFM}
  66.  
  67. { The data is of the following format --                     }
  68. { char arrays are slightly easier to deal with than strings  }
  69. type
  70.   TName = array [0..10] of char;
  71.   TSize = array [0..2] of char;
  72.   TWght = array [0..2] of char;
  73.   TArea = array [0..20] of char;
  74.  
  75. procedure Tani_form.FormCreate(Sender: TObject);
  76. begin
  77. {locate and set the QDB file}
  78. QDB1.FileName:=ChangeFileExt(Application.ExeName,'.qdb');
  79. {we use a cache size that will hold all the items}
  80. QDB1.CacheSize:=128*1024;
  81. {we want to start at the beginning}
  82. QDB1.FirstItem;
  83. end;
  84.  
  85. {every time we move through the database we do this ...}
  86. procedure Tani_form.QDB1Navigate(Sender: TObject);
  87. var
  88.   Item: TMemoryStream;
  89.   Name: TName;
  90.   Size: TSize;
  91.   Wght: TWght;
  92.   Area: TArea;
  93. begin
  94. {prepare a place for the item}
  95. Item:=TMemoryStream.Create;
  96. try
  97.   {get it from the current place in the database}
  98.   QDB1.Get(Item);
  99.   {put the textual data on the form}
  100.   Item.Read(Name,SizeOf(Name));
  101.   Edit1.Text:=Name;
  102.   Item.Read(Size,SizeOf(Size));
  103.   Edit2.Text:=Size;
  104.   Item.Read(Wght,SizeOf(Wght));
  105.   Edit3.Text:=Wght;
  106.   Item.Read(Area,SizeOf(Area));
  107.   Edit4.Text:=Area;
  108.   Image1.Picture.BitMap.LoadFromStream(Item);
  109. finally
  110.   Item.Free;
  111. end;
  112. end;
  113.  
  114. procedure Tani_form.FormDestroy(Sender: TObject);
  115. begin
  116. QDB1.FileName:='';
  117. end;
  118.  
  119. end.
  120.