Topic: Replace System Dialog Message with Own Error Message

Hello MVD,

I'd like to replace the following error with my own Message, it happens when you use the SendMail function
and it takes too long to resolve.  The e-mails actuallly are sent after a little delay but this read timed out error
shows up.  I'd like to replace that message with my own to le the user know that the e-mail will still be sent
out.  Thanks! 

P.S. I tried using the function below to adapt it but could not work it out:

// global event for all exceptions related database
function OnSQLException(Sender: TObject; Msg: string; SQL: string): boolean;
begin
    // exception from button Form1.Button6
    if Sender = Form1.Button6 then
    begin
        if Pos('FOREIGN KEY constraint failed', Msg)=1 then
        begin
            result := True; // to prevent system message
            MessageBox('Selected record contains...', 'Error', MB_OK+MB_ICONWARNING);
        end;
    end;
end;[img]

[/img]
Post's attachments

Attachment icon error.png 2.46 kb, 146 downloads since 2019-09-09 

Re: Replace System Dialog Message with Own Error Message

Hello.


OnSQLException works only with database errors.



Please download latest beta version
https://www.dropbox.com/s/53bhjcbbu6jr3 … a.zip?dl=0


How to replace error message


    try
    if SendMail(Form1.edServer.Text, Form1.edUsername.Text, Form1.edPassword.Text, Trunc(Form1.edPort.Value), Form1.edFrom.Text, Form1.edTo.Text, Form1.edSubject.Text, Form1.mmMessage.Text, Form1.edFileName.Text) then
        ShowMessage('Message sent');
    except
        if Pos('read timed out error', ExceptionMessage)>0 then ShowMessage('Your own message') else ShowMessage(ExceptionMessage);
    end;
Dmitry.

Re: Replace System Dialog Message with Own Error Message

DriveSoft wrote:

Hello.


OnSQLException works only with database errors.



Please download latest beta version
https://www.dropbox.com/s/53bhjcbbu6jr3 … a.zip?dl=0


How to replace error message


    try
    if SendMail(Form1.edServer.Text, Form1.edUsername.Text, Form1.edPassword.Text, Trunc(Form1.edPort.Value), Form1.edFrom.Text, Form1.edTo.Text, Form1.edSubject.Text, Form1.mmMessage.Text, Form1.edFileName.Text) then
        ShowMessage('Message sent');
    except
        if Pos('read timed out error', ExceptionMessage)>0 then ShowMessage('Your own message') else ShowMessage(ExceptionMessage);
    end;

Thank you Dmitry!!