Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/DBExpress    [ Add a report in this area ]  
Report #:  78666   Status: Closed
"Mismatched in datapacket" with DSUtil.StreamToDataPacket
Project:  Delphi Build #:  14.0.3513.24210
Version:    14.0 Submitted By:   Chee Yang Chau
Report Type:  Crash / Data loss / Total failure Date Reported:  10/15/2009 3:44:39 AM
Severity:    Critical / Show Stopper Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   277616
Resolution: Fixed (Resolution Comments) Resolved in Build: : 15.0.3841.32415
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
StreamToDataPacket is a private method used by StreamToVariant in unit DSUtil.pas.  It has an implementation problem.

Steps to Reproduce:
Run the following code and you will encounter "mismatched in datapacket"

var D: OleVariant;
    S: TStream;
    C: TClientDataSet;
  C := TClientDataSet.Create(nil);
  S := TMemoryStream.Create;
    C.FieldDefs.Add('Name', ftString, 20);
    VariantToStream(C.Data, S);
    S.Position := 0;
    StreamToVariant(S, D);
    C.Data := D;
procedure StreamToDataPacket(const Stream: TStream; out VarBytes: OleVariant);
  P: Pointer;
  ByteCount: Integer;
  Size: Int64;
  Stream.Read(Size, 8);
  ByteCount := Integer(Size);
  if ByteCount > 0 then
    VarBytes := VarArrayCreate([0, ByteCount-1], varByte);
    P := VarArrayLock(VarBytes);
      Stream.Position := 0;  // <--- Line A
      Stream.Read(P^, ByteCount);
      Stream.Position := 0;
    VarBytes := Null;

Remove "Line A" and it should work fine.

You may refer to

Richard Werning at 4/12/2010 7:53:13 AM -
Confirmed this still happens in D2010, DSUtil.StreamToDataPacket shouldn't be resetting the Stream.position to 0 - the first 8 bytes are for the size.

Server Response from: ETNACODE01