Why does TFDMemTable->SaveToStream() throw an AV

48 Views Asked by At

I am trying to convert TFDMemTable to a JSON String. I am trying to utilize SaveToStream function, but it throws an NULL Access Violation.

Project XXX raised exception class $C0000005 with message 'access violation at 0x545c8d4f: read of address 0x00000008'.

A reproducible code below:

  TFDMemTable *fd = new TFDMemTable(NULL);

  TFieldDef *Field = fd->FieldDefs->AddFieldDef();
  Field->Name = "Name";
  Field->DataType = Db::ftString;
  Field->Size = 100;

  fd->Open();
  fd->Insert();

  fd->FieldByName("Name")->AsString = "Johnny";

  fd->Post();

  TStringStream *Stream = new TStringStream();

  fd->SaveToStream(Stream, sfJSON); 

I tried with dropping a TFDStanStorageJSONLink also tried creating TStringStream with a String.

IDE: Rad Studio 11.1. We had a similar working peice of code before upgrading from 10.1 Berlin. Thanks.

1

There are 1 best solutions below

0
On

The code above is fine, the problem is with the upgraded project file. If I try in a new project, it works. Ended up creating a new project file. My upgrade wows continues.