 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
madshelgi Guest
|
Posted: Fri Dec 17, 2004 3:35 pm Post subject: OnWorkBegin, OnWork and OnWorkEnd events never get called wi |
|
|
I'm writing a program which downloads a stream of data using the IdHTTP
component. Now I want to put a progress bar on the form so the user can
see, that something is happening.
I've been reading in the help file and as far as I can tell, I should
use the OnWorkBegin, OnWork and OnWorkEnd events to update the progress
bar.
Now, the streaming of data is working fine, I use this call:
IdHTTP.Get(theURL, theStream);
and the data is recieved and displayed on the form, but the work events
are never called (I've got breakpoints in every one).
What am I doing wrong?
Oh, I use Delphi 7 and Indy 9.
Thanks in advance,
madshelgi
--- posted by geoForum on http://delphi.newswhat.com
|
|
| Back to top |
|
 |
Daniel Hobert Guest
|
Posted: Fri Dec 17, 2004 6:35 pm Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
Are you creating the indy component on the fly or did you just drop it onto
the form?
If you're creating it on the fly then you'll need to assign the procedures
to the events (ie myIDHttp.OnWorkBegin := myOnWorkBegin).
Otherwise, have you checked to make sure that the component object has the
event procedures in question assigned to it? This is the only thing I can
think of because I have used the components many times and done just the
kind of handling on those events that you describe.
Cheers,
Daniel Hobert
"madshelgi" <mh (AT) whackmail (DOT) com> wrote
| Quote: | I'm writing a program which downloads a stream of data using the IdHTTP
component. Now I want to put a progress bar on the form so the user can
see, that something is happening.
I've been reading in the help file and as far as I can tell, I should
use the OnWorkBegin, OnWork and OnWorkEnd events to update the progress
bar.
Now, the streaming of data is working fine, I use this call:
IdHTTP.Get(theURL, theStream);
and the data is recieved and displayed on the form, but the work events
are never called (I've got breakpoints in every one).
What am I doing wrong?
Oh, I use Delphi 7 and Indy 9.
Thanks in advance,
madshelgi
--- posted by geoForum on http://delphi.newswhat.com
|
|
|
| Back to top |
|
 |
Don Siders Guest
|
Posted: Fri Dec 17, 2004 6:42 pm Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
| Quote: | I've been reading in the help file and as far as I can tell, I should
use the OnWorkBegin, OnWork and OnWorkEnd events to update the progress
bar.
Now, the streaming of data is working fine, I use this call:
IdHTTP.Get(theURL, theStream);
and the data is recieved and displayed on the form, but the work events
are never called (I've got breakpoints in every one).
What am I doing wrong?
|
Probably nothing.
In Indy 9, the Content-Length header from the HTTP response is not used on stream reads (IOW when GET is called with a response Stream argument). It simply reads until disconnected. So no work events get triggered.. or rather BeginWork gets called with the size 0 (meaning the size is unknown).
Indy 10 implements it differently, and uses the Content-Length header when present.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Dec 17, 2004 8:07 pm Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
"Don Siders" <nanook (AT) joesgarage (DOT) org> wrote
| Quote: | In Indy 9, the Content-Length header from the HTTP response
is not used on stream reads
|
Yes, it is:
procedure TIdCustomHTTP.ReadResult(AResponse: TIdHTTPResponse);
//...
begin
if Assigned(AResponse.ContentStream) then // Only for Get and Post
begin
if AResponse.ContentLength > 0 then // If chunked then this is
also 0
begin
try
ReadStream(AResponse.ContentStream,
AResponse.ContentLength);
except
on E: EIdConnClosedGracefully do
end;
end
else
begin
if AnsiPos('chunked',
AResponse.RawHeaders.Values['Transfer-Encoding']) > 0 then {do not localize}
begin // Chunked
//...
end
else begin
if not AResponse.HasContentLength then
ReadStream(AResponse.ContentStream, -1, True);
end;
end;
end;
end;
Even if it weren't, the OnWork events would still be triggered, just with
the AWorkCountMax value set to 0.
| Quote: | IOW when GET is called with a response Stream argument.
|
All GET requests go through that method anyway, so there is always a
response Stream available. "Get(String): String" uses a TStringStream
internally.
| Quote: | It simply reads until disconnected.
|
Only if the Content-Length is not available and the transfer is not chunked.
| Quote: | So no work events get triggered..
|
Whether or not the ContentLength is present has no bearing whatsoever on the
OnWork events begin triggered. They are always triggered.
| Quote: | or rather BeginWork gets called with the size 0 (meaning the size is
unknown). |
You just contradicted yourself. First you said that the events are not
triggered at all. Now you say that they actually are, just with different
parameters. Those are VERY different statements.
| Quote: | Indy 10 implements it differently, and uses the Content-Length header
when present.
|
The piece of code that handles reading the response is the same logic in
both Indy 9 and 10. They differ only in that Indy 10 uses TIdStreamVCL
whereas Indy 9 doesn't.
Gambit
|
|
| Back to top |
|
 |
Don Siders Guest
|
Posted: Fri Dec 17, 2004 9:08 pm Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
| Quote: | In Indy 9, the Content-Length header from the HTTP response
is not used on stream reads
Yes, it is:
procedure TIdCustomHTTP.ReadResult(AResponse: TIdHTTPResponse);
//...
begin
if Assigned(AResponse.ContentStream) then // Only for Get and Post
begin
if AResponse.ContentLength > 0 then // If chunked then this is
also 0
begin
try
ReadStream(AResponse.ContentStream,
AResponse.ContentLength);
except
on E: EIdConnClosedGracefully do
end;
|
I stand corrected.
| Quote: | or rather BeginWork gets called with the size 0 (meaning the size is
unknown).
You just contradicted yourself. First you said that the events are not
triggered at all. Now you say that they actually are, just with different
parameters. Those are VERY different statements.
|
I stand corrected, again.
|
|
| Back to top |
|
 |
madshelgi Guest
|
Posted: Sat Dec 18, 2004 9:00 am Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
| Quote: | If you're creating it on the fly then you'll need to assign the
procedures
to the events (ie myIDHttp.OnWorkBegin := myOnWorkBegin).
Bingo! I hadn't done that. And I am creating it on the fly... |
So now the OnWorkEnd event is triggered and also OnWorkBegin with
AWorkCount showing the size of the file I'm streaming - no problems
there.
But for some mysterious reason the OnWork event doesn't get triggered.
Any ideas?
I'm new at this Indy business, so any information is greatly appreciated.
Regards
madshelgi
--- posted by geoForum on http://delphi.newswhat.com
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Dec 18, 2004 10:38 am Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
"madshelgi" <mh (AT) whackmail (DOT) com> wrote
| Quote: | But for some mysterious reason the OnWork event doesn't get triggered.
|
How large is the file that you are downloading? If it is small, then perhas
the entire file is being read in a single block, thus OnWork is not needed
between OnWorkBegin and OnWorkEnd.
GAmbit
|
|
| Back to top |
|
 |
madshelgi Guest
|
Posted: Sat Dec 18, 2004 10:52 am Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
| Quote: | How large is the file that you are downloading? If it is small, then
perhas
the entire file is being read in a single block, thus OnWork is not
needed
between OnWorkBegin and OnWorkEnd.
|
The file is 261 KB, but now I'm gonna try a bigger one.
madshelgi
--- posted by geoForum on http://delphi.newswhat.com
|
|
| Back to top |
|
 |
madshelgi Guest
|
Posted: Sat Dec 18, 2004 10:59 am Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never get calle |
|
|
Nope, tried a bigger one (8000 KB), still no OnWork event reaction.
madshelgi
--- posted by geoForum on http://delphi.newswhat.com
|
|
| Back to top |
|
 |
madshelgi Guest
|
Posted: Sat Dec 18, 2004 11:36 am Post subject: Re: OnWorkBegin, OnWork and OnWorkEnd events never getcalled |
|
|
Damn!!!
Stupid, stupid me!!!
I mentioned in my first post that I use D7 and Indy 9, and what do I do?
I'm writing a test application with Delphi 8 while I'm trying to figure
this problem out.
So when I went back to Delphi 7 and tried it there, it worked perfectly!
Why do I have both Delphi 7 and 8, you ask? Well, I just got Delphi 8
from my boss and I haven't yet had the chance to use it very much, so I
thought I would fool around with it a bit now, but alas...
Makes me wonder though, why I couldn't get it to work in Delphi 8 and
Indy 10...
Anyway, thanks for helping!
madshelgi
--- posted by geoForum on http://delphi.newswhat.com
|
|
| 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
|
|