#1 2015-06-12 09:58:36

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Memory Exception in SynCrossPlatformJSON with TSQLRawBlob

Hi AB

I try to assign a TMemoryStream with size = 272421 to a TSQLRawBlob

First i tried this easy method - which raises an exception converting the Bytes to JSON (at approx. 40 Bytes before the end..):

LStream : TMemoryStream;
..
rec.BinaryData := TByteDynArray(LStream.Memory);
..
Client.Update(rec, 'Binarydata') <-- Exception $C0000005 in BytesToBase64JSONString Here something goes wrong

Now i experimented a little and found a working solution. But i don't really know if this is the optimum cause it also raises an exception in a special case

LStream : TMemoryStream;
aDaten : Pointer;
..

try
  rec := TBinaryRecord.Create;
...
  try
    GetMem(aDaten, LZipStream.Size);
    LStream.Position := 0;
    LStream.ReadBuffer(aDaten^, LStream.Size);
    rec.Binaerdaten := TByteDynArray(aDaten);
    Client.Update(rec, 'BinaryData');
  finally
//    FreeMem(aDaten); // commented out cause of exception in rec.Free
  end;
finally
  rec.Free;   <-- Raises Exception if i use FreeMem(aDaten)
end;

Now my question: What is the prefered way to assign a TMemoryStream Content to a TSQLRawBlob using CrossPlatform Client ?

Last edited by itSDS (2015-06-12 10:00:26)


Rad Studio 12.1 Santorini

Offline

#2 2015-06-12 10:50:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Memory Exception in SynCrossPlatformJSON with TSQLRawBlob

You are mixing TByteDynArray and pointers variables there...
Those two types are perfectly incompatible.
Writing TByteDynArray(aDaten) and TByteDynArray(LStream.Memory) do compile, but would raise GPF at runtime.

A TByteDynArray is not just a memory pointer, it is a special kind of content, with a length and reference count encoded before the data.

Offline

#3 2015-06-13 06:19:18

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Memory Exception in SynCrossPlatformJSON with TSQLRawBlob

Hi AB - i was a little bit stupid - thanks for your hint smile


Rad Studio 12.1 Santorini

Offline

Board footer

Powered by FluxBB