Solved

Error handling in Delphi 1.0

Posted on 1997-10-16
5
196 Views
Last Modified: 2010-04-04
Hi...

I am a student who is beginning to use Delphi 1.0 .
Would you pleez send me an explaination of how to and/or the specific code on :

1) While entering information into a database, if the wrong type of information is entered into a field of a specific type Delphi produces an error causing the program to stop.
An example would be, when alphanumeric data is entered into a numeric field and the record is posted, an error is produced and the program is terminated.

I need help on how to handle this error by giving the user an error message without terminating the program so that the user can go back and correct such a problem.

2) When one tries to post data into a table that is not in edit or insert mode, an error is produced and the program terminates. This is in the case where one uses a DBNAVIGATOR button.
 
How does one go about avoiding such termination by being able to provide the user with a suitable message to go back correct the situation.

If my questions are not sufficiently clear or ambigious, please provide any helpful information and coding on one goes about handling errors in Delphi 1.0.

Your attention will be highly appreciated.

Yours sincerely  
Sprawler.
0
Comment
Question by:sprawler
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
mirek071497 earned 50 total points
ID: 1347777
Hi
You must use try..except  or  try..finally statements

example

var
  st : string;
  lk : integer;
begin
  st :='23a3';
  try
    { place here instruction which can fail }
    lk := StrToInt( st );
  except
    { this was called on error }
    showmessage( 'bad integer format' );
  end;
end;
0
 

Author Comment

by:sprawler
ID: 1347778
Hi.. Again mirek

I am uncertain what code would go into the areas you labelled :

{Place here instruction which could fail}
{This was called on error}

Please suggest code using an example, if possible.
Tanx for the speedy response to my question.

sprawler
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1347779
Hi

if you get exception at any code then you could place this after the "try". When the "try" starting then all exceptions jump to the code after "except".

Sorry but my english is poor so i don't understand which example you need. Do you need example with TTable ?
Mayby you don't know wher to place the try..except ? If yes then I think so you have code which make the post and you must place the try..except there.
0
 

Author Comment

by:sprawler
ID: 1347780
Hi again .....

An example of an error routine that you have used  or one that you could think up would be fine.  

Lets say that I am trying to enter data into a Table and the field requires an 8 digit number that is a primary key. Instead of typing in 8 digits,  I type in  7 digits. An error is displayed and the program terminates. how woul one program such an EXCEPTION.

Tanx
sprawler





0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1347781
Hi
sorry for the long time.

You must tell me more. Which database (DBF,Paradox ... ) and please submit your fields definition and simple code. I will try to help you.

BTW if you try use exceptions then please not in delphi because then you get always Exception from Delphi not from your proc. So compile program and run without delphi. I remember that you can set this in options, but now i don't know where.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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