0

I have a problem with saving data to stream with a ClientDataSet.

I put data in the ClientDataSet and try to:

...
var
strmBENU: TMemoryStream;


implementation    
...

TForm1.Button1Click(Sender: TObject);
begin
  ClientDataSet1.SaveToStream(strmBENU);
end;

...

Clicking Button1, here is what I get:

Access violation at adress 0049CEB2 in module 'Project2.exe'. Reading address 00000000.

What am I doing wrong?

Acron
  • 1,378
  • 3
  • 20
  • 32

2 Answers2

3

Probably the stream is not created. Try this:

TForm1.Button1Click(Sender: TObject);
var
  strmBENU: TMemoryStream;
begin
  strmBENU := TMemoryStream.Create;
  try
    ClientDataSet1.SaveToStream(strmBENU);
    // do stuff with stream
  finally
    strmBENU.Free;
  end;
end;
Kcats
  • 884
  • 1
  • 15
  • 26
2

Looks like a NULL reference. Have you instantiated strmBENU?

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • Nice, i instantiated it and now it says when i try to ClientDataSet2.LoadfromStream(strBENU) An exception has been thrown in project2.exe: EDatabaseError: 'ClientDataSet2: Missing Data-Provider or DataPackage.' Process stopped. – Acron Aug 07 '09 at 11:01
  • forgot to insert the Provider Name on the CDS2. but loading from stream and then opening CDS2 gives me no data in my TDBGrid2 – Acron Aug 07 '09 at 11:38
  • failed due to some noob error not connecting the datasource to the DBGrid. Question now it. how to get that over sockets... but that is another question already opend. http://stackoverflow.com/questions/1244465/software-design-tier-2-application-with-clientdataset-and-sockets – Acron Aug 07 '09 at 13:12