Can't terminate an application in the 'except' portion of a 'try..except' [Edit]

I'm a long time Delphi 5 user, recently switched to Delphi XE... and I'm having trouble getting a program to terminate if an exception is raised. Here's the code:

procedure TForm1.FormCreate(Sender: TObject);
begin
  try
    DFCom.Open
  except
    showmessage('Invalid Com Port number');
    application.Terminate;
  end;
end;

In this code, 'DFCom' is an async serial port device. If the exceptino occurs, I want to notify the user via the 'showmessage' mechanism, and then abort the program. When I run this (with an invalid port number assigned to the DFCom property), the 'showmessage' appears, but I can't click it off and abort.... it's simply stuck there... can't even click the red 'x' on the 'showmessage' window. This happens both in the IDE, as well as when running the compiled executable.

Can anyone help me? Explain why this doesn't work?

EDITED TO ADD: If I get rid of the 'showmessage' statement, the application terminates as expected.


Edited by: Norm Bernstein on Jul 5, 2011 7:19 AM

Edited by: Norm Bernstein on Jul 5, 2011 7:40 AM
0
Norm
7/5/2011 2:40:37 PM
embarcadero.delphi.oodesign 456 articles. 0 followers. Follow

3 Replies
785 Views

Similar Articles

[PageSpeed] 3

"Norm Bernstein" wrote in message news:375101@forums.embarcadero.com...
> I'm a long time Delphi 5 user, recently switched to Delphi XE... and I'm 
> having trouble getting a program to terminate if an exception is raised. 
> Here's the code:
>
> procedure TForm1.FormCreate(Sender: TObject);
> begin
>  try
>    DFCom.Open
>  except
>    showmessage('Invalid Com Port number');
>    application.Terminate;
>  end;
> end;
>
> In this code, 'DFCom' is an async serial port device. If the exceptino 
> occurs, I want to notify the user via the 'showmessage' mechanism, and 
> then abort the program. When I run this (with an invalid port number 
> assigned to the DFCom property), the 'showmessage' appears, but I can't 
> click it off and abort.... it's simply stuck there... can't even click the 
> red 'x' on the 'showmessage' window. This happens both in the IDE, as well 
> as when running the compiled executable.
>
> Can anyone help me? Explain why this doesn't work?
>
> EDITED TO ADD: If I get rid of the 'showmessage' statement, the 
> application terminates as expected.


Generally it is always an problem to kill the application while it is still 
in the process of creating the application and main form. The form's 
OnCreate event is called as part of still being in the form's constructor 
and so it continues to finish its creation even after calling Terminate.

You can try calling Halt here but a better method would be to provide a 
method (either in Form1 or in a non-UI code unit) that does whatever checks 
or tests are needed, whether that be just your DFCom.Open call above or more 
than that, and call that from your .dpr unit prior to the call to create the 
main form. If it indicates a problem, do not even create the main form but 
halt execution right there. That way you also avoid the flash of the main 
form being created and displayed just to have it dissappear again.


-- 
Wayne Niddery (TeamB)
HEALTH TIP: If you can't afford a doctor, go to an airport - you'll get a 
free x-ray and a breast exam and; if you mention Al Qaeda you'll get a free 
colonoscopy.
0
Wayne
7/5/2011 3:58:56 PM
> Generally it is always an problem to kill the application while it is still 
> in the process of creating the application and main form. The form's 
> OnCreate event is called as part of still being in the form's constructor 
> and so it continues to finish its creation even after calling Terminate.
> 
> You can try calling Halt here but a better method would be to provide a 
> method (either in Form1 or in a non-UI code unit) that does whatever checks 
> or tests are needed, whether that be just your DFCom.Open call above or more 
> than that, and call that from your .dpr unit prior to the call to create the 
> main form. If it indicates a problem, do not even create the main form but 
> halt execution right there. That way you also avoid the flash of the main 
> form being created and displayed just to have it dissappear again.
> 
> 
> -- 
> Wayne Niddery (TeamB)


Thanks for the response... although it appears that the problem has nothing to do with trying to halt the program in an exception block.. instead, it appears that the problem is the 'showmessage' function itself. I have the same problem elsewhere in the program with the 'inputquery' function; when I call either of these, the little window appears, but it's unresponsive to clicking on 'OK' or 'cancel', or even rhe 'red x'. 

I've been using Delphi 5 for years, but I'm brand new to XE, so this came as quite a shock... why isn't the program resuming execution at the next statement after hitting the OK button?
0
Norm
7/5/2011 4:21:30 PM
The problem was diagnosed in my other thread.... thanks for the views and help.

Norm Bernstein
0
Norm
7/6/2011 12:53:28 PM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;ferd@farkel.net&gt;= <br /> To: "support-firefox@lists.mozilla.org" &lt;support-firefox@lists.mo= zilla.org&gt;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

'''
Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this fee...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

'b'..'a'
Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim; On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0'...

'IN' Clause or 'OR'
Hello, [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR COL1='valu3'. TABLEA is a huge table and it has non-clustered index on COL1. Among the above 2 queries, which query will give me the better performance or fast response and WHY? What is the difference between 'IN' and 'OR' clauses as for as Sybase Optimization is concerned. Which is the better one to be used on huge tables. Thanks. Mac An IN list is treated ...

'or' or 'union'
Hello I was just wondering, in general what is better to use, an 'or' clause in a select or a 'union' to join two selects together. Do both statements create work tables? Many thanks Alex I think OR will be better than union. because suppose u have 3 tables and using OR u can join table a and table b and table c so each table will have only one read. but using union you will join table a and table b and in another query of union u will use table (a or b) and table c so ur one read is more in union . Ramdas Alex Cheung wrote: > Hello > >...

Again with the 'reset' and 'can't be found' stuff...
Name: William Jones Email: jbillyjonesatyahoodotcom Product: Firefox Summary: Again with the 'reset' and 'can't be found' stuff... Comments: Hello Again FireFox, Listen...I'm just a simple guy, a 'dial-up baby boomer' who's had to learn the hard way all the way through. I recently sent a similar e-mail requesting assistance with this ridiculous and incessant 'pop up' that informs me that 'my connection has been reset', and/or, 'a problem locating page'....huh? I was just on the damn thing and even switching from one ...

'NMDayTim', 'Psock' , 'NMTime' , 'NMFtp' can not be opened.
hello, my colleague have developed an application under c++ builder 5. so now i should undertake it and optimize it. last days i have installed the C++ Builder 2010 testversion to get some experience on it, because i have not used it before. when i try to compile the old project in C++ builder 2010, comes some Compile errors. Also, there are some Includes like 'NMDayTim', 'Psock' , 'NMTime' , 'NMFtp' in this old Project. they can be found and compiled in the old c++ Builder 5. but not in c++ builder 2010. so i want to know do i solve this problem or go...

XPath
Hi allI'm trying to use XPath to select a node in a Word document saved as XML.I'm looking for a <w:t> node with the value '«test_Title»'.Problem is, I get the 'Invalid token' exception because it doesn't like the chevron characters.Anyone aware of how I might escape them?ThanksDavid Hi,     Can you please provide us the xPath expression used for selecting the nodes.-Sri-------------------------------------------------If this post was useful to you, please mark it as answer. Thank you! Hi there//w:t[contains(.,'«test_Title»')] Th...

Web resources about - Can't terminate an application in the 'except' portion of a 'try..except' [Edit] - embarcadero.delphi.oodesign

Resources last updated: 12/18/2015 12:03:19 PM