{*********************************************************}
{                                                         }
{                     MightyQuery                         }
{            SQL Database Management Software             }
{                                                         }
{   Original developer: Zlatko Matić, 2009-2011           }
{             e-mail: matalab@gmail.com                   }
{  Milkovićeva 6, Mala Ostrna, 10370 Dugo Selo,  Croatia. }
{                                                         }
{*********************************************************}

{-----------------------------------------------------------------------------

The Initial Developer of the Original Code is Zlatko Matić
(matalab@gmail.com or matic.zlatko@gmail.com).

Contributor(s):

Last Modified: 04.06.2011

Known Issues:

History (Change log):
  version 1.0.4, date 04.06.2011 :
		MightyQuery released as free software
-----------------------------------------------------------------------------}

unit Unit4;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, fpcsvexport, FileUtil, LResources, Forms, Controls,
  Graphics, Dialogs, ExtCtrls, EditBtn, StdCtrls, Unit1,
  db, ZMConnection, ZMQueryDataSet;

type

  { TFormExportToCSV }

  TFormExportToCSV = class(TForm)
    Button1: TButton;
    CSVExporter1: TCSVExporter;
    FileNameEdit1: TFileNameEdit;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
    FDataSet:TZMQueryDataSet;
  public
    { public declarations }
    constructor Create(var pDataset: TZMQueryDataset);
  end; 

var
  FormExportToCSV: TFormExportToCSV;

implementation

procedure TFormExportToCSV.Button1Click(Sender: TObject);
begin
  try
    CSVExporter1.FileName:=FileNameEdit1.FileName;
    CSVExporter1.Execute;
    ShowMessage('Dataset is successfully exported to the file: '+ CSVExporter1.FileName);
  except
    on E:Exception do begin
      ShowMessage(' I could not export the dataset. '+E.Message);
    end;
  end;
end;


constructor TFormExportToCSV.Create(var pDataset: TZMQueryDataset);
begin
  FDataset:=pDataset;
  CSVExporter1.Dataset:=FDataset;
  //Open the form FormFilters.
  try
    FormExportToCSV.Visible:=True;
  except
    on E:Exception do begin
      ShowMessage('Error while trying to open the form "FormExportToCSV". '+ E.Message);
    end;
  end;
end;

initialization
  {$I unit4.ctrs}

end.

