Board index » delphi » How to stop showing 'Key Violation' in Delphi

How to stop showing 'Key Violation' in Delphi

Hi *.*

 I've a strange problem. Currently I'm using Delphi 5 with BDE and MS-SQL 2k. My Db has a Table and this table has a Uninqe Index , When program tries to update with a repeated item this message appeared:

' Key Violation '
' Can not insert duplicate item ....'

I've used TRY EXCEPT but on my Source & Exe file first the above message showes then my own message.

What's your suggestion? What can I do? Is it a Bug?

Thanks in Advance

 

Re:How to stop showing 'Key Violation' in Delphi


H_, Please find some questions below:

"HOA" <hove...@hotmail.com> wrote

Quote
>  ... this table has a Unique Index. When program tries to update

By "update" do you mean Edit or Insert?

Quote
> with a repeated item this message appeared:
>  > ' Key Violation '   ' Can not insert duplicate item ....'
> I've used TRY EXCEPT but on my Source & Exe file
> first the above message showes then my own message.

I do not understand the sentence above.

Quote
> What's your suggestion? What can I do? Is it a Bug?

What would you like the user to see when they try to insert a row
with a key that matches a key already in the table?

Regards, JohnH

Re:How to stop showing 'Key Violation' in Delphi


"John Herbster (TeamB)" <herb-sci1_at_sbcglobal.net> skrev i en meddelelse
news:3ef86918$2@newsgroups.borland.com...

Quote
> > I've used TRY EXCEPT but on my Source & Exe file
> > first the above message showes then my own message.

> I do not understand the sentence above.

He doesn't know that the IDE show the exception first, before his own
message in the except part is shown.
--
Finn Tolderlund

Re:How to stop showing 'Key Violation' in Delphi


Hi,

I want to insert a new row but the IDE shows the mentioned message then shows my own message. i.e. I want to show 'Number is not Unique'

I know IDE first show the error, I can run or stop the excutation but here I've received 3 message, IDE and then 'KEY Violation' and then muy own Message.

Thanks,

Re:How to stop showing 'Key Violation' in Delphi


"HOA" <hove...@hotmail.com> wrote

Quote
> I want to insert a new row, but the IDE shows the
> mentioned message, then shows my own message.
> i.e. I want to show 'Number is not Unique'

Hoa,  Does you program work properly when run outside
of the IDE?  Regards, JohnH

Re:How to stop showing 'Key Violation' in Delphi


Quote
>Hoa,  Does you program work properly when run outside
>of the IDE?  Regards, JohnH

NO, instead of 3 message I get 2 messages. Key Violation and My own.

Re:How to stop showing 'Key Violation' in Delphi


"Hoa" <hove...@hotmail.com> wrote

Quote
> >Hoa,  Does you program work properly when run outside
> >of the IDE?  Regards, JohnH
> NO, [outside the IDE] instead of 3 message I get 2 messages.
> Key Violation and My own.

Thank you.  Now I understand.  Can you please post the code
between the EXCEPTION and the END of the exception block?
It may help to find the problem.  Regards, JohnH

Re:How to stop showing 'Key Violation' in Delphi


Quote
>Thank you.  Now I understand.  Can you please post the code
>between the EXCEPTION and the END of the exception block?
>It may help to find the problem.  Regards, JohnH

Thanks for you replies. My code is a large one with some custom components so I can't post it for you. I think this error may caused by one of those components so I can't stop Delphi to show the Key Violation ? What's your idea? Is it a Delphi bug? or it's a component bug?

TIA

Re:How to stop showing 'Key Violation' in Delphi


"Hoa" <hove...@hotmail.com> wrote

Quote
> >Thank you.  Now I understand.  Can you please post the code
> >between the EXCEPTION and the END of the exception block?
> >It may help to find the problem.  Regards, JohnH
> Thanks for you replies. My code is a large one ...

Hoa,  How much code is in the EXCEPT .. END block?
I suspect that you are getting more than one execption or are
re-raising the same execption after displaying one of your
own messages.

Quote
> I think this error may be caused by [a custom] component
> so I can't stop Delphi to show the Key Violation?

Why not? I do not understand.  In the IDE, Delphi will stop itself.
Regards, JohnH

Re:How to stop showing 'Key Violation' in Delphi


Sorry! I've made a mistake. I thought you want TRY Except block. The Except .. End Block is :

   Except
       On E: Execption Do
          Application.MessageBox (....)
   End;

Because I'm newbie in Delphi, I don't know if raising errors in custom components also handeld by IDE or not? I've no idea about what happend because the database update ocurres in a component called dbWrapper.

Re:How to stop showing 'Key Violation' in Delphi


Hoa,  Your code below will absorb the exception generated
in the try-block.  However Application.MessageBox is a
function returning the button that the user pressed (see Help).
Are you checking that result?  What happens when you step
through the code?  When does the other exception pop up?
Do you have complicated expressions in place of "...." ?

"Hoa" <hove...@hotmail.com> wrote

Quote
>    Except
>        On E: Execption Do
>           Application.MessageBox (....)
>    End;

 Regards, JohnH

Other Threads