Hello friend is my first time i need to control a insert, edit, delete on dbgrid with register from tsquery
what is best event to validate if record exist when is new record on tsquery event onbeforepost
procedure TDM.ZTDocsBeforePost(DataSet: TDataSet);
begin
if( not ZTDocs.Locate('model ; serie', VarArrayOf([DM.ZTDocs.FieldByName('model').AsString ,DM.ZTDocs.FieldByName('serie').AsString ]), [loCaseInsensitive,loPartialKey])) then begin
ShowMessage('Register with this values already registered');
end;
end;
or
procedure TDM.ZQMDocBeforePost(DataSet: TDataSet);
Var bm:TBookmark;
Modl,ser:String;
begin
bm:=DataSet.Bookmark;
Modl:= Dataset.FieldByName('Model').AsString;
Ser:= DataSet.FieldByName('serie').AsString ;
if( ZQMDoc.Locate('model ; serie', VarArrayOf([Modl ,Ser ]), [loCaseInsensitive,loPartialKey]) ) then begin
Showmessage('Reister with values already exist');
ZQMDoc.Cancel;
end else begin
ZQMDoc.Post;
ZQMDoc.GotoBookmark(bm);
end;
end;
what is better option or some example ro control database error..... or avoid the app crash...