vintagedave / firemonkey-container

Automatically exported from code.google.com/p/firemonkey-container
92 stars 34 forks source link

FireDAC Cursor provider #9

Open ortuagustin opened 8 years ago

ortuagustin commented 8 years ago

When using FireDAC, you must include a Cursor provider for your application to work

There are 3 cursor providers that ships with FireDAC: Forms (Vcl), FMX and Console

This is the minimal amount of code that is needed to connect to a database with FireDAC. For the sake of simplicity, I've used SQLite:

unit Unit1;

interface

uses
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.StdCtrls,
  Data.DB,
  FireDAC.Stan.Intf,
  FireDAC.Stan.Option,
  FireDAC.Stan.Error,
  FireDAC.Stan.Def,
  FireDAC.Stan.Pool,
  FireDAC.Stan.Async,
  FireDAC.Stan.ExprFuncs,
  FireDAC.Stan.Param,
  FireDAC.UI.Intf,
  FireDAC.Phys,
  FireDAC.VCLUI.Wait,
  FireDAC.Phys.Intf,
  FireDAC.Phys.SQLite,
  FireDAC.Phys.SQLiteDef,
  FireDAC.DatS,
  FireDAC.DApt,
  FireDAC.DApt.Intf,
  FireDAC.Comp.DataSet,
  FireDAC.Comp.Client;

type
  TForm1 = class(TForm)
    FDConnection1: TFDConnection;
    FDQuery1: TFDQuery;
    FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
    Button1: TButton;   
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  System.SysUtils;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FDConnection1.Params.Database := ChangeFileExt(ParamStr(0), 'sdb');
  FDConnection1.Connected := True;
  FDConnection1.ExecSQL('CREATE TABLE IF NOT EXISTS Test (SomeText VARCHAR(30) NOT NULL)');
  FDQuery1.Open('SELECT * FROM Test ');
end;

end.

Adding FMX.Forms to the uses (either interface or uses) of the unit caused the following exception to be raised:

Object factory for class {3E9B315B-F456-4175-A864-B2573C4A2201} is missing. To register it, you can drop component [TFDGUIxWaitCursor] into your project.

The same problem can be reproduced by adding Parnassus.FMXContainer on the interface uses section. Since Parnassus.FMXContainer refers to FMX.Forms in the interface uses section it's expected that it reproduces the problem

Workaround: Add the FMX provider aswell, that is, add FireDAC.FMXUI.Wait to the interface uses section

This application works:

unit Unit1;

interface

uses
  System.Classes,
  FMX.Forms,
  Parnassus.FMXContainer,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.StdCtrls,
  Data.DB,
  FireDAC.Stan.Intf,
  FireDAC.Stan.Option,
  FireDAC.Stan.Error,
  FireDAC.Stan.Def,
  FireDAC.Stan.Pool,
  FireDAC.Stan.Async,
  FireDAC.Stan.ExprFuncs,
  FireDAC.Stan.Param,
  FireDAC.UI.Intf,
  FireDAC.Phys,
  FireDAC.VCLUI.Wait,
  FireDAC.FMXUI.Wait,
  FireDAC.Phys.Intf,
  FireDAC.Phys.SQLite,
  FireDAC.Phys.SQLiteDef,
  FireDAC.DatS,
  FireDAC.DApt,
  FireDAC.DApt.Intf,
  FireDAC.Comp.DataSet,
  FireDAC.Comp.Client;

type
  TForm1 = class(TForm)
    FDConnection1: TFDConnection;
    FDQuery1: TFDQuery;
    FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
    Button1: TButton;
    FireMonkeyContainer1: TFireMonkeyContainer;
    procedure FireMonkeyContainer1CreateFMXForm(var Form: TCommonCustomForm);
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  System.SysUtils,
  System.UITypes,
  FMX.Graphics;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FDConnection1.Params.Database := ChangeFileExt(ParamStr(0), 'sdb');
  FDConnection1.Connected := True;
  FDConnection1.ExecSQL('CREATE TABLE IF NOT EXISTS Test (SomeText VARCHAR(30) NOT NULL)');
  FDQuery1.Open('SELECT * FROM Test ');
end;

procedure TForm1.FireMonkeyContainer1CreateFMXForm(var Form: TCommonCustomForm);
begin
  Form := FMX.Forms.TForm.CreateNew(Self);
  // put some color on the form, so we can actually see it
  FMX.Forms.TForm(Form).Fill.Kind := TBrushKind.Solid;
  FMX.Forms.TForm(Form).Fill.Color := clBlack;
  Form.Show;
end;

end.