Solved

Debug Error Handling

Posted on 2009-04-10
5
173 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
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
8080_Diver earned 250 total points
Comment Utility
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
Comment Utility
Thanks for your reply.
except E:Exception  <========= Undeclaired Identifier......
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
Add SysUtils to the uses clause
0
 

Author Comment

by:Grant Fullen
Comment Utility
wow thats   weard I allready have SysUtils in my uses clause...........
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now