 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andy Guest
|
Posted: Sat Apr 29, 2006 11:03 am Post subject: Help with array of TStream |
|
|
I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of TStream
this way, but for some reason, it compiles fine but does not execute fine.
for Idx:=Low(BmpStreams) to High(BmpStreams) do begin
AStream:=TMemoryStream.Create;
try
Pic:=TPicture.Create;
try
//this is where the problem happens
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
....
finally
FreeAndNil(Pic);
end;
finally
FreeAndNil(AStream);
end;
end;
Thanks in advance.
Andy |
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Sat Apr 29, 2006 12:03 pm Post subject: Re: Help with array of TStream |
|
|
Andy wrote:
| Quote: | I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of TStream
this way, but for some reason, it compiles fine but does not execute fine.
|
You need to say what you mean by "Does not execute fine"!
| Quote: | for Idx:=Low(BmpStreams) to High(BmpStreams) do begin
AStream:=TMemoryStream.Create;
try
Pic:=TPicture.Create;
try
//this is where the problem happens
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
|
You don't show any code which could load anything into the stream. My
guess is that you forgot to rewind the stream before trying to load from it:
BmpStreams[Idx].Seek(0,soFromBeginning);
or:
BmpStreams[Idx].Position:=0;
(For some reason I prefer the former.. )
Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org |
|
| Back to top |
|
 |
Frank Soriano Guest
|
Posted: Sat Apr 29, 2006 7:03 pm Post subject: Re: Help with array of TStream |
|
|
Before this line:
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
BmpStream[Idx].Position :=0;
will fix your problem.
btw, why you need this "AStream:=TMemoryStream.Create;" ?
Frank
"Andy" <aadiabo (AT) ix (DOT) netcom.com> wrote in message
news:44533ad1$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of
TStream this way, but for some reason, it compiles fine but does not
execute fine.
for Idx:=Low(BmpStreams) to High(BmpStreams) do begin
AStream:=TMemoryStream.Create;
try
Pic:=TPicture.Create;
try
//this is where the problem happens
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
....
finally
FreeAndNil(Pic);
end;
finally
FreeAndNil(AStream);
end;
end;
Thanks in advance.
Andy
|
|
|
| Back to top |
|
 |
Andy Guest
|
Posted: Sat Apr 29, 2006 10:03 pm Post subject: Re: Help with array of TStream |
|
|
Hi Frank,
Thanks so much Frank for replying. I have a strong feeling that this will
fix my problem.
Thanks again for helping out.
Andy
"Frank Soriano" <franksoriano (AT) programmer (DOT) net> wrote in message
news:4453aa07 (AT) newsgroups (DOT) borland.com...
| Quote: | Before this line:
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
BmpStream[Idx].Position :=0;
will fix your problem.
btw, why you need this "AStream:=TMemoryStream.Create;" ?
Frank
"Andy" <aadiabo (AT) ix (DOT) netcom.com> wrote in message
news:44533ad1$1 (AT) newsgroups (DOT) borland.com...
I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of
TStream this way, but for some reason, it compiles fine but does not
execute fine.
for Idx:=Low(BmpStreams) to High(BmpStreams) do begin
AStream:=TMemoryStream.Create;
try
Pic:=TPicture.Create;
try
//this is where the problem happens
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
....
finally
FreeAndNil(Pic);
end;
finally
FreeAndNil(AStream);
end;
end;
Thanks in advance.
Andy
|
|
|
| Back to top |
|
 |
Andy Guest
|
Posted: Sat Apr 29, 2006 10:03 pm Post subject: Re: Help with array of TStream |
|
|
Hi Nicholas,
Thanks so much for replying. Sorry I was a little vague on the error. I had
madexcept on but it just gave me an AV notification and nothing else. And
the ignorance on my part on this didn't help.
I will give the modification a try. Chances are I think you are right about
the problem.
Thanks so much for your help.
Andy
"Nicholas Sherlock" <N.sherlock (AT) gmail (DOT) com> wrote in message
news:44534e43 (AT) newsgroups (DOT) borland.com...
| Quote: | Andy wrote:
I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of
TStream this way, but for some reason, it compiles fine but does not
execute fine.
You need to say what you mean by "Does not execute fine"!
for Idx:=Low(BmpStreams) to High(BmpStreams) do begin
AStream:=TMemoryStream.Create;
try
Pic:=TPicture.Create;
try
//this is where the problem happens
Pic.Graphic.LoadFromStream(BmpStreams[Idx]);
You don't show any code which could load anything into the stream. My
guess is that you forgot to rewind the stream before trying to load from
it:
BmpStreams[Idx].Seek(0,soFromBeginning);
or:
BmpStreams[Idx].Position:=0;
(For some reason I prefer the former.. )
Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org |
|
|
| Back to top |
|
 |
Nicholas Sherlock Guest
|
Posted: Sun Apr 30, 2006 12:03 am Post subject: Re: Help with array of TStream |
|
|
Andy wrote:
| Quote: | I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of TStream
this way, but for some reason, it compiles fine but does not execute fine.
|
Remember that you have to create the streams that are in the array
before you use them. The code you show creates an unnecessary stream.
Are you sure that you really need more than one stream?
Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org |
|
| Back to top |
|
 |
Andy Guest
|
Posted: Wed May 03, 2006 8:03 am Post subject: Re: Help with array of TStream |
|
|
Hi Nicholas,
Yes, I am aware of the creation of the streams. The extra stream was for
something else in the code. But thanks for giving me the heads up.
Andy
"Nicholas Sherlock" <N.sherlock (AT) gmail (DOT) com> wrote in message
news:4453f8b2$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Andy wrote:
I'm having a problem with the following code and I was hoping a good
samaritan could help out. I'm not sure you could create an array of
TStream this way, but for some reason, it compiles fine but does not
execute fine.
Remember that you have to create the streams that are in the array before
you use them. The code you show creates an unnecessary stream. Are you
sure that you really need more than one stream?
Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|