Page 1 of 1

Check for duplicates before post

Posted: Sat 06 Jul 2013 12:30
by vanmeir
Hello,

I would like to know if there is a strategy for checking (preventing) duplicate records (or specific fields within records) before the current record will be posted?
The purpose of this is to be able to notify the user for incorrect values and keep the option for the user to cancel the edit.
Important to say is that i'm using cachedupdates mode!

Regards,

Frans

Re: Check for duplicates before post

Posted: Mon 08 Jul 2013 09:33
by AndreyZ
Hello,

There is no built-in mechanism that allows checking of duplicate records in the CachedUpdates mode. You can use the BeforePost event to check it yourself and abort the posting in case of existence of duplicate records. Please note that the only way to cancel posting in the BeforePost event is to call the Abort method. This functionality is inherited from the TDataSet standard class. For more information, please read the BeforePost event description in the Delphi help.

Re: Check for duplicates before post

Posted: Mon 08 Jul 2013 11:17
by vanmeir
Hello Andrey,

the problem in this case is that calls like Locate and FindKey can lead to a jump to another record.
Maybe it's better to rephrase the question: is there a method availlable to search or check for values within a dataset without changing/disturbing (the state of) the current record?

Re: Check for duplicates before post

Posted: Tue 09 Jul 2013 08:01
by AndreyZ
To avoid changing of the current record, you should use bookmarks. Here is a code example:

Code: Select all

var
  bm: TBookmark;
begin
  bm := MSQuery.Bookmark; // save the current position
  MSQuery.Locate(KeyFields, KeyValues, Options);
  MSQuery.GotoBookmark(bm); // return to the saved position
end;

Re: Check for duplicates before post

Posted: Wed 05 Aug 2020 07:00
by AntonPlotnikov2018
I have the same issue. Locate is not accepted because I should check duplicates before posting. Is this a way to scan underlying in-memory storage without changing the current record and its state?

Re: Check for duplicates before post

Posted: Tue 06 Oct 2020 13:51
by Stellar
Unfortunately, we couldn't reproduce the issue. To investigate this behavior of SDAC, please compose a small sample demonstrating the issue and send it to us, including database objects creating scripts.
You can send the sample using the contact form at our site: devart.com/company/contactform.html