BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with array of TStream

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Thirdparty Tools (General)
View previous topic :: View next topic  
Author Message
Andy
Guest





PostPosted: Sat Apr 29, 2006 11:03 am    Post subject: Help with array of TStream Reply with 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
Nicholas Sherlock
Guest





PostPosted: Sat Apr 29, 2006 12:03 pm    Post subject: Re: Help with array of TStream Reply with quote



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.. Smile)

Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org
Back to top
Frank Soriano
Guest





PostPosted: Sat Apr 29, 2006 7:03 pm    Post subject: Re: Help with array of TStream Reply with 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...
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





PostPosted: Sat Apr 29, 2006 10:03 pm    Post subject: Re: Help with array of TStream Reply with quote

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





PostPosted: Sat Apr 29, 2006 10:03 pm    Post subject: Re: Help with array of TStream Reply with quote

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.. Smile)

Cheers,
Nicholas Sherlock
--
http://www.sherlocksoftware.org
Back to top
Nicholas Sherlock
Guest





PostPosted: Sun Apr 30, 2006 12:03 am    Post subject: Re: Help with array of TStream Reply with quote

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





PostPosted: Wed May 03, 2006 8:03 am    Post subject: Re: Help with array of TStream Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Thirdparty Tools (General) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.