🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.nativeapi.win32
7 messages
7 total messages Started by Monzer George Yazigi Fri, 25 Jul 2008 16:00
Stream Read Error
#222
Author: Monzer George Yazigi
Date: Fri, 25 Jul 2008 16:00
16 lines
1190 bytes
Dear All,
I need to copy the content of TMemoryStream to an TBArray =  Array of
Byte.

I have the following code, and I am getting Stream Read Error.

     MS:=TMemoryStream.Create;
     imgView.IO.SaveToStreamJpeg(MS);
     SZ:=MS.Size;
     SetLength(img,SZ);
     MS.ReadBuffer(img, SZ);

Where imgView is a TImageEn component that has a JPG file loaded
within it. 

Any advise?
Re: Stream Read Error
#223
Author: John Herbster
Date: Fri, 25 Jul 2008 16:24
20 lines
1532 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote
> I need to copy the content of
> TMemoryStream to an TBArray =  Array of Byte.
> I have the following code, and I am getting Stream Read Error.
 
>     MS:=TMemoryStream.Create;
>     imgView.IO.SaveToStreamJpeg(MS);
>     SZ:=MS.Size;
>     SetLength(img,SZ);
>     MS.ReadBuffer(img, SZ);

Monzer,

While I do not know the type of "img", 
I guess that you need something like
  If SZ > 0
    then MS.ReadBuffer(img[0], SZ);

HTH, JohnH
Re: Stream Read Error
#224
Author: Monzer George Yazigi
Date: Fri, 25 Jul 2008 16:52
28 lines
1617 bytes
Hi John,
Sorry I missed writing it in my message. img is of type TBArray.

Regards

On Fri, 25 Jul 2008 11:24:44 -0500, "John Herbster"
<herb-sci1_AT_sbcglobal.net> wrote:

>
>"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote
>> I need to copy the content of
>> TMemoryStream to an TBArray =  Array of Byte.
>> I have the following code, and I am getting Stream Read Error.
> 
>>     MS:=TMemoryStream.Create;
>>     imgView.IO.SaveToStreamJpeg(MS);
>>     SZ:=MS.Size;
>>     SetLength(img,SZ);
>>     MS.ReadBuffer(img, SZ);
>
>Monzer,
>
>While I do not know the type of "img", 
>I guess that you need something like
>  If SZ > 0
>    then MS.ReadBuffer(img[0], SZ);
>
>HTH, JohnH
Re: Stream Read Error
#225
Author: Pieter Zijlstra
Date: Fri, 25 Jul 2008 17:02
28 lines
1626 bytes
Monzer George Yazigi wrote:

> Dear All,
> I need to copy the content of TMemoryStream to an TBArray =  Array of
> Byte.
> 
> I have the following code, and I am getting Stream Read Error.
> 
>      MS:=TMemoryStream.Create;
>      imgView.IO.SaveToStreamJpeg(MS);

After saving to a memory stream the position within the stream is at
the end of the stream, you'll need to set it back to from where you
want to start to read.

       MS.Position := 0;  // or use MS.Seek(0, soBeginning)

>      SZ:=MS.Size;
>      SetLength(img,SZ);
>      MS.ReadBuffer(img, SZ);

How is img defined? Is it a dynamic array of byte?
In that case you need to use img[0] instead.

       MS.ReadBuffer(img[0], SZ);

-- 
Pieter
Re: Stream Read Error
#227
Author: Peter Below (TeamB)
Date: Fri, 25 Jul 2008 17:24
31 lines
1719 bytes
Monzer George Yazigi wrote:

> Dear All,
> I need to copy the content of TMemoryStream to an TBArray =  Array of
> Byte.
> 
> I have the following code, and I am getting Stream Read Error.
> 
>      MS:=TMemoryStream.Create;
>      imgView.IO.SaveToStreamJpeg(MS);
>      SZ:=MS.Size;
>      SetLength(img,SZ);
>      MS.ReadBuffer(img, SZ);
> 
> Where imgView is a TImageEn component that has a JPG file loaded
> within it. 
> 
> Any advise?

a) you fail to set the MS.Position to 0 before you start reading from
it.
b) you need to pass img[0] to ReadBuffer to get the correct address
passed. Your current code would overwrite memory at the location of the
img variable.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Re: Stream Read Error
#226
Author: Monzer George Yazigi
Date: Fri, 25 Jul 2008 17:27
33 lines
1783 bytes
Many thanks Pieter.

It worked.


On Fri, 25 Jul 2008 19:02:25 +0200, "Pieter Zijlstra"
<p.zylstra.notthis@hccnet.nl> wrote:

>Monzer George Yazigi wrote:
>
>> Dear All,
>> I need to copy the content of TMemoryStream to an TBArray =  Array of
>> Byte.
>> 
>> I have the following code, and I am getting Stream Read Error.
>> 
>>      MS:=TMemoryStream.Create;
>>      imgView.IO.SaveToStreamJpeg(MS);
>
>After saving to a memory stream the position within the stream is at
>the end of the stream, you'll need to set it back to from where you
>want to start to read.
>
>       MS.Position := 0;  // or use MS.Seek(0, soBeginning)
>
>>      SZ:=MS.Size;
>>      SetLength(img,SZ);
>>      MS.ReadBuffer(img, SZ);
>
>How is img defined? Is it a dynamic array of byte?
>In that case you need to use img[0] instead.
>
>       MS.ReadBuffer(img[0], SZ);
Re: Stream Read Error
#228
Author: Remy Lebeau (TeamB)
Date: Fri, 25 Jul 2008 17:27
20 lines
1440 bytes
"Monzer George Yazigi" <monzer_yazigi@hotmail.com> wrote in message 
news:6vtj845qfu28o0f27q2lb4rjq76s1c6q34@4ax.com...

>     imgView.IO.SaveToStreamJpeg(MS);

You are not setting the stream's Position back to 0 before calling 
ReadBuffer():

    MS.Position := 0;

>     MS.ReadBuffer(img, SZ);

Because you are using a dynamic array, you have to index into its first 
element in order to pass the correct memory address to ReadBuffer():

    MS.ReadBuffer(img[0], SZ);


Gambit 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads