[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Key Viloation canceling post in OnBeforePost

Posted on 1999-12-13
4
Medium Priority
?
250 Views
Last Modified: 2008-03-10
Ok, so I have a TDBGrid, in the OnBeforePost event of the table (=TDBGrid.DataSource.DataSet) I ask the user a question, if they say no I cancel the post by calling table.cancel. This line is executed but I then get an EDbEngineError exception saying there is a key Violation, Violation of primary index constraint, cannot insert duplicate key in object table. The record being cancelled does not have a duplicate key anyway. Why is this happening? (I have tried raising an exception, which works, but closes the app.) I just want it to cancel and let the user continue. What am I doing wrong?
0
Comment
Question by:boardtc
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2278108
hi tom,

try this in your beforepost-event

If the_User_Said_No then
Begin
  Table1.Cancel;  //Cancel edit or Insert
  Abort;              //Cancel the post
end;

you must abort the post,
because the post goes forward if you don't abort it,
and the db-engine is after the cancel never be able for a post,
which causes in an exception
(the Cancel does not end the post)

meikl
0
 

Author Comment

by:boardtc
ID: 2278161
Meikl, cheers, that worked well. How do you recommend that I return the focus of the grid to the first cell, is returns now at the last cell where I pressed tab to go onto the next record (which called the OnBeforePost and resultant cancel). I tried resetting the focus but that has no effect since the grid is already focused, table.first does not work either. Thanks, Tom.
0
 

Author Comment

by:boardtc
ID: 2278823
Meikl, please answer to grade. Setting SelectedField worked for the above.

Regards, Tom.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 2278923
good morning tom,

well, glad that this works,
good luck again,

meikl ;-)

puh, i've sleepy eyes, this morning
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

608 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