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
Description
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;
begin
  C := TClientDataSet.Create(nil);
  S := TMemoryStream.Create;
  try
    C.FieldDefs.Add('Name', ftString, 20);
    C.CreateDataSet;
    VariantToStream(C.Data, S);
    S.Position := 0;
    StreamToVariant(S, D);
    C.Close;
    C.Data := D;
  finally
    S.Free;
    C.Free;
  end;
end;
Workarounds
procedure StreamToDataPacket(const Stream: TStream; out VarBytes: OleVariant);
var
  P: Pointer;
  ByteCount: Integer;
  Size: Int64;
begin
  Stream.Read(Size, 8);
  ByteCount := Integer(Size);
  if ByteCount > 0 then
  begin
    VarBytes := VarArrayCreate([0, ByteCount-1], varByte);
    P := VarArrayLock(VarBytes);
    try
      Stream.Position := 0;  // <--- Line A
      Stream.Read(P^, ByteCount);
      Stream.Position := 0;
    finally
      VarArrayUnlock(VarBytes);
    end;
  end
  else
    VarBytes := Null;
end;

Remove "Line A" and it should work fine.

You may refer to http://chee-yang.blogspot.com/2009/10/datasnap-in-process-iappserver.html
Attachment
None
Comments

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