Topic: FOREIGN KEY

Hello MVD!

in the default of MVD, if there is a connection to a child table you can not delete the mother table record unless you delete first the children record... My point of view, is there a trap or customized message box not show the existing error message by MVD.

Thanks!

2 (edited by ehwagner 2019-07-16 15:16:41)

Re: FOREIGN KEY

Here is an example of trapping an SQL system message and presenting your own message:


function OnSQLException(Sender: TObject; Msg: string; SQL: string): boolean;
begin
    // exception from button Form1.Button1
    if Sender = Form1.Button1 then
    begin
        if Pos('FOREIGN KEY constraint failed', Msg)=1 then
        begin
            result := True; // to prevent system message
            MessageBox('Your customized message here', 'Error', MB_OK+MB_ICONERROR);
        end;
    end;
end;

Another way to do it is to check, through script, the existence of child records before you attempt the delete of the parent. And if they exist then present your own message.

Re: FOREIGN KEY

Thanks Ehwagner!