Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: closing an application over the network
| Subject: | Re: closing an application over the network |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 19 Dec 2007 16:18:19 |
"soonic" <xxsoonic@op.pl> wrote in message
news:4769a0a1$1@newsgroups.borland.com...
> Please, how the code should look
You shouldn't really be relying on the OnDisconnected event to begin with.
Indy is not an event-driven library. When you call Disconnect() yourself,
then you can obviously call Terminate() at the same time as well. As for
when you are not closing the socket yourself yet, an exception is thrown
when a disconnect occurs during a reading/writing operation, so simply wrap
your reading/writing code in a try..except block to handle it.
> Well, I run my application "test.exe" when I exit, I want
> to delete the file by it self.
An executable cannot delete itself. The file is locked while the executable
is running, and the executable wouldn't be able to execute any deletion code
unless it is running. Catch 22.
The only way to do what you are asking for is to either:
1) launch another executable that deletes the first one after it has fully
terminated
2) register the executable via MoveFileEx() or the Registry so it is deleted
by the OS the next time the OS is restarted
Gambit