Manually create a IDADataSet containing a dynamic set of field an values (Delphi)

Hi,

We want to return a IDADataSet that contains dynamic fields and values.
Normally we return a DataSet like this:


dataSet := fConnection.NewDataset(selectSql, ‘FutureValues’);
dataSet.Open;
result := Binary.Create;
DataStreamer.WriteDataset(Result, dataSet, [woRows, woSchema], -1)

Where selectSql contains a dynamically build sql statement.
This works fine.

In some other cases we want to return a DataSet that will contain a single row and data that cannot be expressed as a sql statement.
Basically we would like to do something like
DataSet.Fields.Add…
DataSet.Fields[x].Value :=
DataStreamer.WriteDataset(Result, dataSet, [woRows, woSchema], -1)

Is this possible???.

I tried to do this, but got an error about a RemoteDataAdapter not being assigned (I guess because this is suppoes to be used client side)

memTable := TDACDSDataTable.Create(Nil);
memTable.LogicalName := ‘FutureValues’;
singleField := memTable.FIelds.Add;
singleField.DataType := datString;
singleField.Size := 30;
singleField.SQLOrigin := ‘naam’;
singleField.DisplayName := ‘Naam’;

memTable.Open;
memTable.Insert;
memTable.AddRecord([‘naam’], [‘Test’]);
memTable.Post;
memTable.First;
DataStreamer.WriteDataset(Result, memTable, [woRows, woSchema], -1)

regards
Paul Sjoerdsma

Hello,
Please do the following:

  1. Use TDAMemDataTable instead of TDACDSDataTable.
  2. Set TDAMemDataTable.RemoteFetchEnabled to False

Aah, ok I forgot to mention that we are still using an old version of RemObjects (actually still using Delphi 2007).
We are within 2 months are moving to Delphi XE and latest RemObjects, but for now we do not have TDAMemDataTable…

Hello,

  1. Set TDACDSDataTable.RemoteFetchEnabled to False
  2. AddRecord contains Insert and Post. Don’t use them together.
    In your case:
 
................................
memTable.Open;

memTable.Insert;
memTable.FieldByName('naam').AsString := 'Test';
memTable.Post;
//or
memTable.AddRecord(['naam'], ['Test']);

memTable.First;

Hi,
This is the code I have

memTable := TDACDSDataTable.Create(Nil);
memTable.RemoteFetchEnabled := False;
memTable.LogicalName := ‘FutureValues’;

singleField := memTable.Fields.Add;
singleField.DataType := datString;
singleField.Size := 30;
singleField.SQLOrigin := ‘naam’;
singleField.DisplayName := ‘Naam’;

memTable.Open;
memTable.FieldByName(‘naam’).asString := ‘Test’;

memTable.Post;

memTable.First;

When this code is executed I get an error : “Cannot find field Item1” in
procedure TDACustomFieldCollection.Bind(aDataset: TDataset);
This happens on the memtable.Open call

By the way we are using version 4.0.19.565

regards
Paul

Ok, it seems I forgot to set a property singleField.Name
Seems to work better now