Unique index / onEditError / onPostError
Posted: Sat 06 Jan 2018 15:46
Hi
I use a onEditError and onPostError procedure to see if a NAME already exist.
This is done by creating a unique index on this field. I use the code below to check if
the name is unique.
Normaly there is only 1 unique field called NAME. Now i also have to check if the DATE is
also unique. So i need the following checks :
- field NAME unique OR
- field DATE unique
how can that be done and show the user WHAT is wrong...the NAME or the DATE!
I use a onEditError and onPostError procedure to see if a NAME already exist.
This is done by creating a unique index on this field. I use the code below to check if
the name is unique.
Normaly there is only 1 unique field called NAME. Now i also have to check if the DATE is
also unique. So i need the following checks :
- field NAME unique OR
- field DATE unique
how can that be done and show the user WHAT is wrong...the NAME or the DATE!
Code: Select all
procedure TdmProduction.ProductionDayEditError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
begin
{
if (E is EMyError) then begin
if (EMyError(E).ErrorCode=ER_DUP_KEY) then begin
Application.MessageBox(PCHAR('The name '+ UpperCase(ProductionDay.fieldByName('Name').AsString)+' already exists!.'), 'Message', MB_OK+MB_ICONEXCLAMATION+MB_DEFBUTTON1+MB_APPLMODAL);
ProductionDay.cancel;
Abort;
end;
end;
}