unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids, ExtCtrls, DBCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Table1: TTable;
    Table2: TTable;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    DBNavigator1: TDBNavigator;
    DBNavigator2: TDBNavigator;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Button3: TButton;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var rek:integer;
begin
  rek:=0;
  Table2.First;
  while not Table2.Eof do
  begin
   rek:=rek+1;
   Table2.Next;
  end;
  Label1.Caption:='Liczba wypożyczonych książek '+IntToStr(rek);
end;

procedure TForm1.Button2Click(Sender: TObject);
var roznica:extended;
begin
  Label2.Caption:='';
  Table2.First;
  while not Table2.Eof do
  begin
   roznica:=Date-Table2.FieldByName('Data').AsDateTime;
   //lub ta sama instrukcja inaczej, w/g helpa bezpieczniej:
   //roznica:=Date-Table2.Field[2].AsDateTime;
   if roznica>30 then
   Label2.Caption:=Label2.Caption+'Upłynął termin zwrotu książki pt.' +
   Table2.Fields[1].AsString+' Liczba dni od wypożyczenia to '+IntToStr(Round(roznica))+#13;
   Table2.Next;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Table1.Close;
  Table2.Close;
  Application.Terminate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Caption:='Biblioteka '+DateToStr(Date);
  Table1.TableName:='bibl1.dbf';
  Table1.Active:=true;
  Table2.TableName:='bibl2.dbf'; //lub GetCurrentDir+'\bibl2.dbf';
  Table2.Active:=true;
end;

end.
