1 (edited by v_pozidis 2018-03-12 09:41:18)

Topic: Avoid error message

Hi,
When I try to  delete a record that it is related with  other tables I get an error which is correct.
How can a (procedure) routine to get an other custom message instead the below
like the 'Translate' function


https://i.imgur.com/4d4KIYy.png

Thank you in advance
Vassilis

Re: Avoid error message

// global event for all exceptions related database
function OnSQLException(Sender: TObject; Msg: string; SQL: string): boolean;
begin
    // exception from button frmStoixeia.Button4
    if Sender = frmStoixeia.Button4 then
    begin
        if Pos('FOREIGN KEY constraint failed', Msg)=1 then
        begin
            result := True; // to prevent system message
            MessageBox('Your Message Here.', 'Error', MB_OK+MB_ICONWARNING);
        end;
    end;
end;

Re: Avoid error message

Super great !!!!!!!
Thank you.

Re: Avoid error message

Hi ehwanger,
can you help me please?

The  Message'' Cannot make a visible window modal''

Can I translate the message in an other language using the Translate function. or is there another way?

I ask you because you had help me in the past.

http://img4.imagetitan.com/img.php?image=17_modal.png

Thank you in advance
Vassilis






ehwagner wrote:
// global event for all exceptions related database
function OnSQLException(Sender: TObject; Msg: string; SQL: string): boolean;
begin
    // exception from button frmStoixeia.Button4
    if Sender = frmStoixeia.Button4 then
    begin
        if Pos('FOREIGN KEY constraint failed', Msg)=1 then
        begin
            result := True; // to prevent system message
            MessageBox('Your Message Here.', 'Error', MB_OK+MB_ICONWARNING);
        end;
    end;
end;

Re: Avoid error message

v_pozidis,
I'm not sure if the Translate function will work with that message. You can try it. But I would say probably not. This is not really a user error. You probably have something going wrong in a script accessing a form and should be fixed rather than trying to translate the message.. Can you attach your project and I or someone can take a look.

Re: Avoid error message

I know where the problem is. I thought instead this message is could create amother one.
Thanks anyway.