Solved

Debug Error Handling

Posted on 2009-04-10
5
179 Views
Last Modified: 2012-05-06
I have a small querry . It works of but if you press cancel small problem in debuger.
I need a way to handle it.

By the way it only does this in the debuger.
If i just run the exe it will do nothing. Is this someing to be worried about ?
var
  value : string;
 
begin
    value := InputBox('Invoice Number Lookup ', 'Please type your Number', '');
 if datamodule2.ADOQuery1.Locate('InvoiceNumber', Value, []) then
  ShowMessage('Record located')
  else
  ShowMessage('Record NOT LOCATED');
end;

Open in new window

large.jpg
0
Comment
Question by:Grant Fullen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
8080_Diver earned 250 total points
ID: 24120683
It works of but if you press cancel small problem in debuger.
I need a way to handle it.

Please explain what you mean by "if you press cancel".  If you are referring to the Cancel button on the Dialog box, then you need to look at the Default String parameter in your InputBox statement . . . it is a null string.  That could weel be the cause of your problems.  If you do not want toeven attempt to locate a record, then you need to code for that.
Also, you should get in the habit of using TRY . . . EXCEPT . . . END; to wrap code that has a potential for throwing exceptions.  That lets you, among other things, add a little more debugging or human consumable text to the error message (see below).  
Substituting the code snippet for your code should, among other things, make the exception message a little more meaningful if in no other way than that it will show you what was entered for the search parameter.  


var
  value : string;
 
begin
  value := InputBox('Invoice Number Lookup ', 
                    'Please type your Number', '');
  if  (Value = '')
  then begin
    ShowMessage('You clicked Cancel.');
  end
  else
    try
      if datamodule2.ADOQuery1.Locate('InvoiceNumber', Value, []) 
      then begin
        ShowMessage('Record located');
      end
      else begin
        ShowMessage('Record NOT LOCATED');
      end; {if}
    except E:Exception
      on exception
        begin
          Raise Exception.Create('ERROR: An error occured while ' +   
                                 'trying to locate the desired ' +   
                                 'record [' + Value + ']:' + #13#10 +
                                 E.Message);
        end;
    end; {try}
  end; {if}
end;

Open in new window

0
 

Author Comment

by:Grant Fullen
ID: 24120790
Thanks for your reply.
except E:Exception  <========= Undeclaired Identifier......
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24121078
Add SysUtils to the uses clause
0
 

Author Comment

by:Grant Fullen
ID: 24122006
wow thats   weard I allready have SysUtils in my uses clause...........
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24122708
uh no, it's a syntax error

 except
      on E:Exception do
        begin
          Raise Exception.Create('ERROR: An error occured while ' +  
                                 'trying to locate the desired ' +  
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question