tags:

views:

261

answers:

2

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?

+2  A: 

Looks like a NULL reference. Have you instantiated strmBENU?

Mitch Wheat
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
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
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
+2  A: 

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
see comment on Mitch Wheats answer
Acron