Board index » delphi » DB Key Violation handling

DB Key Violation handling

I've got Delphi 4 Pro and I'm trying to start with the following lines of
code to handle Key Violations in a table. I thought this would be a simple
start but it's not working. When the Key Violation occurs the
HandleKeyViolation procedure doesn't run. Anyone have a simple bit of code
they can send me or a location in the Help file for a good example. The
table is a Pardox DB. So far a couple of 1200 page books and the Help file
aren't cutting it. Thanks.

    Bill Dunn

  try
    Table1.Post;
    Table1.ApplyUpdates;
  except
    on EDBEngineError do HandleKeyViolation;
  end;

 

Re:DB Key Violation handling


How about trying this:

except
  On E: Exception do handlekeyviolation
end;

If this works then the system is not throwing the expected exception and you
will need to figure out which exception is being thrown.

Quote
Bill Dunn wrote in message <73aV2.12429$95.295...@news2.giganews.com>...
>I've got Delphi 4 Pro and I'm trying to start with the following lines of
>code to handle Key Violations in a table. I thought this would be a simple
>start but it's not working. When the Key Violation occurs the
>HandleKeyViolation procedure doesn't run. Anyone have a simple bit of code
>they can send me or a location in the Help file for a good example. The
>table is a Pardox DB. So far a couple of 1200 page books and the Help file
>aren't cutting it. Thanks.

>    Bill Dunn

>  try
>    Table1.Post;
>    Table1.ApplyUpdates;
>  except
>    on EDBEngineError do HandleKeyViolation;
>  end;

Re:DB Key Violation handling


    This didn't work. I'm still getting the DBEngine Error with a Key
Violation error.
    Is Try and Except the correct item to use? I want the program to
continue even if the Key Violation occurs.

    Bill Dunn

Quote
Robert Dytmire wrote in message ...
>How about trying this:

>except
>  On E: Exception do handlekeyviolation
>end;

>If this works then the system is not throwing the expected exception and
you
>will need to figure out which exception is being thrown.

>Bill Dunn wrote in message <73aV2.12429$95.295...@news2.giganews.com>...
>>I've got Delphi 4 Pro and I'm trying to start with the following lines of
>>code to handle Key Violations in a table. I thought this would be a simple
>>start but it's not working. When the Key Violation occurs the
>>HandleKeyViolation procedure doesn't run. Anyone have a simple bit of code
>>they can send me or a location in the Help file for a good example. The
>>table is a Pardox DB. So far a couple of 1200 page books and the Help file
>>aren't cutting it. Thanks.

>>    Bill Dunn

>>  try
>>    Table1.Post;
>>    Table1.ApplyUpdates;
>>  except
>>    on EDBEngineError do HandleKeyViolation;
>>  end;

Re:DB Key Violation handling


Bill Dunn skrev i meldingen <2DkV2.12858$95.347...@news2.giganews.com>...

Quote
>    This didn't work. I'm still getting the DBEngine Error with a Key
>Violation error.
>    Is Try and Except the correct item to use? I want the program to
>continue even if the Key Violation occurs.

You're aware that this means the record isn't posted at all ??

-------------------------------------
Bj?rge S?ther
REMOVETHIS_bsaet...@online.no

Re:DB Key Violation handling


Quote
On Tue, 27 Apr 1999 10:22:36 -0500, "Bill Dunn" <bil...@vci.net> wrote:
>    This didn't work. I'm still getting the DBEngine Error with a Key
>Violation error.
>    Is Try and Except the correct item to use? I want the program to
>continue even if the Key Violation occurs.

Does this only occur when you run the application from the IDE? Do you have
the IDE debugging facility enabled, where its error trapping preempts any
in the application?

If so:

1. Select Tools|De{*word*81} Options from the Delphi 4 main menu.
2. In the De{*word*81} Options dialog, navigate to the Language Exceptions tab.
3. Uncheck the Stop on Delphi Exceptions checkbox.

After this, the system error dialogs should no longer appear and your
application's exception-handling will be executed.

//////////////////////////////////////////////////////////////////////////
Steve Koterski                   "There are two kinds of pedestrians...the
Technical Publications           quick and the dead."
INPRISE Corporation                            -- Lord Thomas Robert Dewar
http://www.borland.com/delphi                                  (1864-1930)

Re:DB Key Violation handling


    I need oneof the following:

    1) A way to check for a key violation before it happens.
    I can check for a key violation before it happens, but I have to take
the database out of cached update mode to do the search. Well, when I do
that I lose the record I'm trying to add that hasn't been inserted yet.

    or

    2) A way to recover from a key violation without having to restart the
program.
    I could save the field data to variables in the procedure and do error
checking that way but it seems like there should be a much simpler way of
handling key violations.

    From what I understand thus far an exception halts the program. The
program must be restarted. If that is correct then that's not what I want.

    Thanks

    Bill Dunn

Quote
Bj?rge S?ther wrote in message <79lV2.278$ZU2.1...@news1.online.no>...
>Bill Dunn skrev i meldingen <2DkV2.12858$95.347...@news2.giganews.com>...
>>    This didn't work. I'm still getting the DBEngine Error with a Key
>>Violation error.
>>    Is Try and Except the correct item to use? I want the program to
>>continue even if the Key Violation occurs.

>You're aware that this means the record isn't posted at all ??

>-------------------------------------
>Bj?rge S?ther
>REMOVETHIS_bsaet...@online.no

Re:DB Key Violation handling


    What you said raised a question. I was running it from the IDE. When the
IDE error message came up I assumed the program was finished. When I ran it
without the IDE it actually gave me a Key Violation error and the program
continued. Exactly what I wanted. With the notes from another message above
I was able to customize the error message.

    Thanks.

    Bill Dunn

Quote
Steve Koterski wrote in message <3725e492.3417344@newslist>...
>On Tue, 27 Apr 1999 10:22:36 -0500, "Bill Dunn" <bil...@vci.net> wrote:

>>    This didn't work. I'm still getting the DBEngine Error with a Key
>>Violation error.
>>    Is Try and Except the correct item to use? I want the program to
>>continue even if the Key Violation occurs.

>Does this only occur when you run the application from the IDE? Do you have
>the IDE debugging facility enabled, where its error trapping preempts any
>in the application?

>If so:

>1. Select Tools|De{*word*81} Options from the Delphi 4 main menu.
>2. In the De{*word*81} Options dialog, navigate to the Language Exceptions tab.
>3. Uncheck the Stop on Delphi Exceptions checkbox.

>After this, the system error dialogs should no longer appear and your
>application's exception-handling will be executed.

>//////////////////////////////////////////////////////////////////////////
>Steve Koterski                   "There are two kinds of pedestrians...the
>Technical Publications           quick and the dead."
>INPRISE Corporation                            -- Lord Thomas Robert Dewar
>http://www.borland.com/delphi                                  (1864-1930)

Other Threads