Solved

Error handling in Delphi 1.0

Posted on 1997-10-16
5
194 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

11 Experts available now in Live!

Get 1:1 Help Now