When i try to load a Stream to a ClientDataSet i get the following exception:

Mismatch in datapacket

The ClientDataSet has several WideStringfields, so i tried it with an Encoding in TStringStream.Create. If i leave the Encoding out i get an Exception:

Type Mismatch for field XXZ; supposed: TWideString, actual: String

following is my code:

  importStream := TMemoryStream.Create;
  zipImport.ExtractToStream(importName, importStream);
  importStream.Position := 0;

  data := TStringList.Create;
  data.LoadFromStream(importStream);

  importStream.Free;

  Encoding := TEncoding.Unicode;
  ccpStream := TStringStream.Create(Format(FTemplate.Text, [data.Text]), Encoding);

  try
    try

      cdsCCP_Head.LoadFromStream(ccpStream);
...

Before i converted the ClientDataSet to TWideStringField it worked perfect. Can anyone tell me what i can do to read the file?

有帮助吗?

解决方案

The problem was the wrong/old Template from the ClientDataSet.
To create a new template:

  1. go to Designmode and select the ClientDataSet.
  2. Right-Click and 'Create Dataset'.
  3. Select 'Save to MyBase Xml UTF8 table...' and save the new generated xml.

With the new generated Xml the fields are recognized correctly and as @ArnaudBouchez already mentioned, there is no need to decode the stream.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top