Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by bar
Wed, 26 Mar 2008 17:24
Stop the indy Get() function
Author: bar
Date: Wed, 26 Mar 2008 17:24
Date: Wed, 26 Mar 2008 17:24
31 lines
1780 bytes
1780 bytes
Hi All,
If i am calling HTTP->Get(); in main GUI thread and placed TldAntiFreeze
component on the form.
I have a pop-up menu on the form. Each menu item call the following function
to download the .bmp file from the webserver.
void TfrmMain::DownloadFile(String URL)
{
try
{
ErrFile = "";
AnsiString FileName = "SomeFileName.bmp";
std::auto_ptr<TFileStream> strm(new TFileStream(FileName,fmCreate));
HTTP->Request->Pragma = "no-cache";
HTTP->HandleRedirects = true;
HTTP->ReadTimeout = 15000;
HTTP->Get(URL, strm.get());
}
catch(const Exception &E)
{
ErrFile = E.Message;
}
1.I am download a file of 1MB, the process is in progress. I want to set an
option if another menu item is selected while downloading. I want to cancel
the previous download completely, without raising the exception or giving my
own message.
Re: Stop the indy Get() function
Author: Remy Lebeau (TeamB)
Date: Wed, 26 Mar 2008 17:49
Date: Wed, 26 Mar 2008 17:49
18 lines
1766 bytes
1766 bytes
"bar" <shaikakbar250281@yahoo.co.in> wrote in message news:47ea86a8@newsgroups.borland.com... > I want to cancel the previous download completely, > without raising the exception There is no way to do that. The only way to abort the Get() is to either Disconnect() the connection, or raise an Exception in the OnWork event(s). Either one will cause an Exception to escape from Get() into your code, so you must handle it accordingly. If you don't want to show an error message, then you will have to either check the Exception class type and ignore those you know are "safe". Or better, just set a flag somewhere indicating that you caused an intentional exception, and then ignore the error in your exception handler. Gambit
Re: Stop the indy Get() function
Author: bar
Date: Thu, 27 Mar 2008 08:50
Date: Thu, 27 Mar 2008 08:50
9 lines
1198 bytes
1198 bytes
Hi Remy thanks for answering. The function i shown has a problem, Even when the file is not present at the server or if any kind of exception raises. Still the file is creating with 0 bytes. How to avoid this, i mean create the file only if the download success. <g>
Re: Stop the indy Get() function
Author: Remy Lebeau (TeamB)
Date: Thu, 27 Mar 2008 09:41
Date: Thu, 27 Mar 2008 09:41
49 lines
2411 bytes
2411 bytes
"bar" <shaikakbar250281@yahoo.co.in> wrote in message
news:47eb5fc5@newsgroups.borland.com...
> Even when the file is not present at the server or if any
> kind of exception raises. Still the file is creating with 0 bytes.
That is because you are not deleting the file if the download fails.
> How to avoid this, i mean create the file only if the download success.
You have to create the file first before starting the download, or else you
won't have anything to download into (unless you download to memory first,
and then save it to file afterwards). If the download fails, simply delete
the file, for example:
void TfrmMain::DownloadFile(String URL)
{
ErrFile = "";
try
{
String FileName = "SomeFileName.bmp";
try
{
std::auto_ptr<TFileStream> strm(new TFileStream(FileName,
fmCreate));
HTTP->Request->Pragma = "no-cache";
HTTP->HandleRedirects = true;
HTTP->ReadTimeout = 15000;
HTTP->Get(URL, strm.get());
}
catch(const Exception &E)
{
if( !E.InheritsFrom(__classid(EFCreateError)) )
DeleteFile(FileName);
throw;
}
}
catch(const Exception &E)
{
ErrFile = E.Message;
}
}
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