DirectSQL with IBDAC connection

Hi,

I am lookint at SqlDirect sample, and it uses an ADO connection.

My application uses Firebird with IBDAC , Is it possible to use an TIBDAConnection instead of an TADOConnection?

Thanks,
José Carlos.

Hi,

Yes, you should be able to use any provider. FlexCel doesn't know about ADO, FireDac, IBDac, anything: It only knows about TDataSets.

We just choose ado for the examples because it is supported from DXE to XE7 (while for example FireDac wouldn't) and it is available out of the box. But you can use anything.

If you look at the DirectSQL example, you'll see that the only ADO-specific part is the method SetupConnection:

procedure TMainForm.SetupConnection(const Report: TFlexCelReport);
begin
    Report.AddConnection('Northwind',
      function (const sql: string): TDataSet   //We need to return a new TDataSet here, FlexCel will free it.
      var
        ds: TADODataSet;
      begin
        ds := TADODataSet.Create(nil);
        ds.Connection := ADOConnection;
        ds.CommandText := sql;

        Result := ds;
      end);

    Report.AddSqlParameter('StartDate',
      procedure (const ParamName: string; const DataSet: TDataSet)
      begin
        (DataSet as TADODataSet).Parameters.ParamValues[ParamName] := dtStartDate.DateTime;
        (DataSet as TADODataSet).Parameters.ParamByName(ParamName).DataType := ftDateTime;
      end);

    Report.AddSqlParameter('EndDate',
      procedure (const ParamName: string; const DataSet: TDataSet)
      begin
        (DataSet as TADODataSet).Parameters.ParamValues[ParamName] := dtEndDate.DateTime;
        (DataSet as TADODataSet).Parameters.ParamByName(ParamName).DataType := ftDateTime;
      end);

end;

And the part that matters is the method:
Report.AddConnection('Northwind',
      function (const sql: string): TDataSet  

Where you are handled a string and need to return a TDataSet. You can return a TWhateverDataSet here. I don't have IBDAC here, but I've changed the demo to use FireDac, and the changes needed were:

1)Remove the TADOConnection from the main form
2)Add a TFDConnection

Change SetupConnection to be:
procedure TMainForm.SetupConnection(const Report: TFlexCelReport);
begin
    Report.AddConnection('Northwind',
      function (const sql: string): TDataSet   //We need to return a new TDataSet here, FlexCel will free it.
      var
        ds: TFDQuery;
      begin
        ds := TFDQuery.Create(nil);
        ds.Connection := FDConnection;
        ds.SQL.Text := sql;

        Result := ds;
      end);

    Report.AddSqlParameter('StartDate',
      procedure (const ParamName: string; const DataSet: TDataSet)
      begin
        (DataSet as TFDQuery).Params.ParamValues[ParamName] := dtStartDate.DateTime;
        (DataSet as TFDQuery).Params.ParamByName(ParamName).DataType := ftDateTime;
      end);

    Report.AddSqlParameter('EndDate',
      procedure (const ParamName: string; const DataSet: TDataSet)
      begin
        (DataSet as TFDQuery).Params.ParamValues[ParamName] := dtEndDate.DateTime;
        (DataSet as TFDQuery).Params.ParamByName(ParamName).DataType := ftDateTime;
      end);

end;




Yes,  It works like you said.

I am using a TIBCQuery and it is ok.

Thanks,
José Carlos.