User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 456,562 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,507 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 2243 | Replies: 9 | Solved
Reply
Join Date: Oct 2007
Posts: 4
Reputation: Sofo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Sofo Sofo is offline Offline
Newbie Poster

Question Closing the main form (app).

  #1  
Oct 25th, 2007
I have written a small application that sends an Email.
I would like it to terminate itself without any user action.
I end the OnCreate procedure with Self.Close, but the application keeps running.
What am i missing?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Chenoa, IL
Posts: 13
Reputation: bigattichouse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
bigattichouse's Avatar
bigattichouse bigattichouse is offline Offline
Newbie Poster

Re: Closing the main form (app).

  #2  
Oct 25th, 2007
Worst/Quickest/Unelegant method? (assuming you don't just make a console app)

1. Drop a TTimer on the form
2. In the OnTimer event:
Timer1.enabled=false;
SendEmail(); <-- whatever it is you do
self.close

Better/More elegant: If your email has an event "OnSent" or something, you could call self.close there.

Best: console application. Just have it open, create the email components, fire and close.
Reply With Quote  
Join Date: Oct 2007
Posts: 4
Reputation: Sofo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Sofo Sofo is offline Offline
Newbie Poster

Re: Closing the main form (app).

  #3  
Oct 25th, 2007
Thanks for your reply.
There is an ondisconnected event, but it didn't work. The Timer solution did.
Agree about console solution, but i don't have the knowledge to do it.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Closing the main form (app).

  #4  
Oct 26th, 2007
The best way to terminate an application is to call
application.terminate
This prevents a lot of problems and can be called anywhere.

Avoid using tTimer as much as possible because it is a "heavy" object --chewing up resources and time.

Hope this helps.
Reply With Quote  
Join Date: Oct 2007
Posts: 4
Reputation: Sofo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Sofo Sofo is offline Offline
Newbie Poster

Re: Closing the main form (app).

  #5  
Oct 26th, 2007
Originally Posted by Duoas View Post
The best way to terminate an application is to call
application.terminate
This prevents a lot of problems and can be called anywhere.

Avoid using tTimer as much as possible because it is a "heavy" object --chewing up resources and time.

Hope this helps.


Hello and thanks for your reply.
I tried the Application.Terminate (think it's still in there) but it didn't terminate the application.
As it is the Ontimer seems to be the only solution that works. Resources are not a problem since the app. is very small and fast executing.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Closing the main form (app).

  #6  
Oct 26th, 2007
I'd be interested to know why application.terminate didn't stop your program. Have you got unusual hooks in there somewhere? Did your code actually call it?

The problem with the timer is that there is a system limit on the number of timers available. It doesn't matter how big your application is.
Reply With Quote  
Join Date: Oct 2007
Posts: 4
Reputation: Sofo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Sofo Sofo is offline Offline
Newbie Poster

Re: Closing the main form (app).

  #7  
Oct 27th, 2007
Originally Posted by Duoas View Post
I'd be interested to know why application.terminate didn't stop your program. Have you got unusual hooks in there somewhere? Did your code actually call it?

The problem with the timer is that there is a system limit on the number of timers available. It doesn't matter how big your application is.


I had the Application.Terminate in the wrong place it seems. (After Application.Run).
Moving it to the end of the OnCreate (where all the work is done) solved the problem.
Thanks for you'r suggestion.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Closing the main form (app).

  #8  
Oct 27th, 2007
Ah, yes. That would do it. Glad you caught that.
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: Closing the main form (app).

  #9  
Oct 28th, 2007
Guess you are not looking for an alternate solution any more but in case you are - the best thing to do is to create a console app. You should only need to code one unit and from there do the email sending in the initialization section, do any residual housekeeping in the finalization section and you are done.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Closing the main form (app).

  #10  
Oct 28th, 2007
If you are still going to mess with it...

Forget the console app, initialization and finalization, and all those other loops.

Just don't bother creating any forms. Don't call application.run.
Just do your stuff in the application .dpr file's begin..end block, and let the program terminate naturally when it hits the end.
  1. program fooey;
  2. uses Classes;
  3. var
  4. foo: tFileStream;
  5. s: string = 'Hello, world!';
  6. begin
  7. foo := tFileStream.create( 'fooey.txt', fmCreate or fmOpenWrite );
  8. foo.write( pChar( s )^, length( s ) )
  9. end.
Good luck.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 5:42 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC