Can't create an instance of a TDBXReader class

I am writing  DataSnap client and server applications using Embarcadero C++ builder XE3.
I get an error compiling a DataSnap client application when trying to create an instance of TDBXReader()
The DataSnap server returns  a TDBXReader pointer.

The following compiler error is issued.
[bcc32 Error] Clientform.cpp(30): E2353 Class 'TDBXReader' is abstract because of '_fastcall TDBXReader::DerivedNext() = 0'

I understand the message but how do I code the client application to process the TDBXReader pointer ?  
The server code and client code is shown below; The server code compiles and runs.

Client code:

void __fastcall TForm2::Button1Click(TObject *Sender)
  TMyClassClient *Temp;
  TDBXReader *r=NULL;
  void *p;

        SQLConnection1->Connected = true;
        Temp = new TMyClassClient(SQLConnection1->DBXConnection);
        r = new TDBXReader();
      p = r->FieldAddress("Variable");
      Edit1->Text = *((UnicodeString *)p);

      delete Temp;
      delete r;
Server code:

TDBXReader* TMyClass::ATable(void)
      TDBXCommand *comm;

      try {
            comm = DataModule1->SQLConnection1->DBXConnection->CreateCommand();
            comm->CommandType = TDBXCommandTypes_DbxSQL;
            comm->Text = "Select * from Generalconfig";

            if (!comm->IsPrepared) {
            return comm->ExecuteQuery();

      catch (Exception* e) {
            return NULL;

Roger AlcindorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TDBXReader is not to be created, it gets instantiated as a result of TDBXCommand.ExecuteQuery, and then you use the TDBXReader instance to read your records.

Here  is a Delphi example, but the idea should be clear.
procedure Connect;
  connection: TDBXConnection;
  command: TDBXCommand;
  reader: TDBXReader;
  value: TDBXValue;
  valueType: TDBXValueType;
  colCountStr: string;
  i, j: Integer;
  numCols: integer;
  ListBox1: TListBox;
  sqlCommand = 'select * from employee';
  { Open connection to DB. }
  connection := BuildConnectionFromConnectionName('ConnectionName'); { the name of the DB connection }
    { Get command. }
    command := connection.CreateCommand();
      command.Text := sqlCommand;
      { Execute query. }
      reader := command.ExecuteQuery;
        { Get values from DB. }
        if reader.Next then
          numCols := reader.ColumnCount;
          Str(numCols, colCountStr);
          ListBox1.Items.Add('Number of columns = ' + colCountStr);
          j := 1;
            for i := 0 to reader.ColumnCount - 1 do
              valueType := reader.ValueType[i];
              if valueType.DataType = TDBXDataTypes.AnsiStringType then
                value := reader.Value[i];
                ListBox1.Items.Add(valueType.Name + ' = ' + value.GetString);
              end else
          until (j > 100) or not reader.Next;
      { Free resources. }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Subrat (C++ windows/Linux)Software EngineerCommented:
r = new TDBXReader(); // Is not possible as class TDBXReader is a abstract class object creation is not possible. You need to take help of the derive class which implements the pure virtual functions. As suggested above, you can see
TDBXCommand command;
fill this object as suggested above. and then call ExecuteQuery() and store inside TDBXReader*
Roger AlcindorAuthor Commented:
I get an error "Remote error: Dbx.SQL is an unrecognised command type." when I invoke the command->Prepare(); or the command->ExecuteQuery();

This indicates an error from the server. My server is designed to respond to a method named ATable() which returns a TDBXReader* , see the TDBXReader* TMyClass::ATable(void) code in the original question.

I think that your client example assumes a differently functioning DataSnap server ?
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Roger AlcindorAuthor Commented:
I forgot to upload my revised client coderevisedcliwntclode.txt
Roger AlcindorAuthor Commented:
My client code below has got it working.
Much appreciated and many thanks,


            SQLConnection1->Connected = true;
            Temp = new TMyClassClient(SQLConnection1->DBXConnection);
            Temp->ATable();   // invoke rmote server DataSnap function
            reader = Temp->ATable();

                  numcols = reader->ColumnCount;
                                        // handle first record from query ...

Roger AlcindorAuthor Commented:
One more query on the subject, I get an exception error if I invoke TDBXValue ->IsNull method in order to detect a null value in a record. The IsEmpty method also creaes an exception.
The error is Access violation , read of address 0x00000000

I also get the same error calling the TDBXValue ->GetAnsiString() method (only when the record column value is NULL)
Subrat (C++ windows/Linux)Software EngineerCommented:
Before calling those functions You should have a valid TDBXValue object.
Hopefully some time before you are deleting the object and then u r trying to access.Check the code flow.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.