Michael,
You are a hero! Thank you, thank you, thank you. The code below works
through "/////////////////// ".
I hate to impose, but you really seam to know this stuff and perhaps you
might advise me regarding the following two issues:
// I GET A DECOMPRESSION ERROR ON THE NEXT STATEMENT
DecompressBuf(InpBuf,sz,0,OutBuf,OutBytes); // What could be
wrong [maybe not enough sleep here<g>]
// THE FOLLOWING STATEMENT DOES NOT WORK
ADODataSet1.Recordset := vRecordset;
{I would like the data to be available to databound
controls.What is the best way to do this?}
Thanks again,
Robert Baker
procedure TfrmMapping.Button4Click(Sender: TObject);
var
vConnectionString : string;
vConnection : ADO26_TLB._Connection;
vRecordset : ADO26_TLB._Recordset;
vDataset : ADO26_TLB._Recordset;
vMemoryStream : TMemoryStream;
vAdapter : IStream;
OutBuf, InpBuf : Pointer;
OutBytes, sz : Integer;
MStream : TMemoryStream;
ByteArray : TByteDynArray;
pTemp : Pointer;
begin
{ ConnectionString }
vConnectionString := 'Provider=SQLOLEDB.1;Password=;Persist Security
Info=True;User ID=....
{ Create our _Connection object. }
vConnection := CoConnection.Create;
{ Open the _Connection. }
vConnection.Open(vConnectionString, '', '', adConnectUnspecified);
{ Grab the data and stuff it into a _Recordset. }
vRecordset := vConnection.Execute('SELECT field1,field2,...FROM tbl1',
EmptyParam, adCmdText);
{ Do we have any data? }
if not vRecordset.EOF then
begin
{ Create our memory stream. }
vMemoryStream := TMemoryStream.Create;
try
{ Connect the adapter and the memory stream. }
vAdapter := TStreamAdapter.Create(vMemoryStream, soReference);
{ Save the recordset to the adapter using the ADTG format. }
vRecordset.Save(OleVariant(vAdapter), adPersistADTG);
{ The memory stream should now contain the data, thanks to the
adapter. }
if vMemoryStream.Size > 0 then
begin
{ Reset the position. }
vMemoryStream.Position := 0;
{ Compress the memory. }
OutBuf := nil;
OutBytes := 0;
CompressBuf(vMemoryStream.Memory, vMemoryStream.Size, OutBuf,
OutBytes);
if (OutBuf <> nil) and (OutBytes > 0) then
begin
{ Clear the memory stream. }
vMemoryStream.Clear;
{ Write the new data into the Memory Stream}
vMemoryStream.Write(OutBuf, OutBytes);
{ Point the Memory Stream to the beginning}
vMemoryStream.Position := 0;
{Put it into a Byte Array}
ByteArray := ByteArrayFromStream(vMemoryStream);
/////////////////// - SENT IT ACROSS THE WIRE ////////////////
=========== NOW WE ARE ON THE CLIENT SIDE =========
{ Clear the memory stream. }
vMemoryStream.Clear;
pTemp := @ByteArray[0];
{Put it back into the Memory Stream from the Byte Array}
vMemoryStream.Write( pTemp^, Length(ByteArray));
vMemoryStream.Position := 0;
sz := vMemoryStream.size;
if sz > 0 then
try
{ Decompress the Stream into the buffer }
InpBuf := nil;
OutBuf := nil;
GetMem(InpBuf,sz);
{ Read the Stream into the Input Buffer}
vMemoryStream.Read(InpBuf^,sz);
OutBytes := 0;
{ Decompress the Input Buffer into the Output Buffer}
// I GET A DECOMPRESSION ERROR ON THE NEXT STATEMENT
DecompressBuf(InpBuf,sz,0,OutBuf,OutBytes);
if (OutBuf <> nil) and (OutBytes > 0) then
begin
{ Clear the memory stream}
vMemoryStream.Clear;
{ Put it back into the Stream from the decompressed buffer}
vMemoryStream.Write(OutBuf^,OutBytes);
{ Write the new data. }
{ Save the recordset to the adapter using the ADTG format. }
vAdapter := nil;
vAdapter := TStreamAdapter.Create(vMemoryStream, soReference);
vRecordset.GetRows(22,OleVariant(vAdapter), adPersistADTG);
// THE FOLLOWING STATEMENT DOES NOT WORK
ADODataSet1.Recordset := vRecordset;
end;
finally
vMemoryStream.Free;
DecompressedStream.Free;
if InpBuf <> nil then FreeMem(InpBuf);
if OutBuf <> nil then FreeMem(OutBuf);
end;
end;
end;
finally
end;
end;
end;