unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ZConnection, StdCtrls, ExtCtrls, DB, ZAbstractRODataset, ZDataset,
  Grids, DBGrids;

type
  TFMain = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    DBGrid1: TDBGrid;
    dsOsoby: TDataSource;
    ZConnection1: TZConnection;
    ZReadOnlyQuery1: TZReadOnlyQuery;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);

  private

  public

  end;

var
  FMain: TFMain;

implementation

{$R *.dfm}

procedure TFMain.Button1Click(Sender: TObject);
begin
	Close();
end;

procedure TFMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   ZReadOnlyQuery1.Close();
   ZConnection1.Connected := false;
end;

procedure TFMain.FormShow(Sender: TObject);
begin
   DBGrid1.Align := alClient;

   ZConnection1.Connected := false;

   ZConnection1.Database    := 'biblioteka';
   ZConnection1.HostName    := 'localhost';
   ZConnection1.LoginPrompt := false;
   ZConnection1.Password    := 'root2008'; //  Czytelnik ustawia tutaj swoje hasło dostępu do MySQL
   //tojest domyslny port dla MySQL, nie trzeba go ustwaiać
   // ZConnection1.Port     := 3306;
   ZConnection1.Protocol    := 'mysql-5';
   ZConnection1.User        := 'root';

   ZConnection1.Connected := true;


   ZReadOnlyQuery1.Close();
   ZReadOnlyQuery1.SQL.Clear();
   ZReadOnlyQuery1.SQL.Add('select * from OSOBY order by nazwisko, imie');

   try
	   ZReadOnlyQuery1.Open();
   except
   	ShowMessage('Nieprawidłówy kod SQL?');
   end;

end;

end.
