Solved

How to stop MaskEdit exception?

Posted on 2004-08-03
7
2,745 Views
Last Modified: 2008-01-09

I used TMaskEdit, EditMask is shortTime, when I input something wrong such as 1_:00, It will raise an Exception that said 'Invalid input value' and exit the program. Can I stop the exception? If I input wrong,can it just let me input again?
0
Comment
Question by:adamy
7 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 11709575
unit Unit1_Q_21081083;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask;

type
  EWinInet = class(Exception);

  TForm1 = class(TForm)
    MaskEdit1: TMaskEdit;
    Memo_Error: TMemo;
    procedure FormCreate(Sender: TObject);
  private   { Private declarations }
    procedure On_App_Exception(Sender: TObject; E: Exception);
  public    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  UnitMsgShow;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := On_App_Exception;
end;

procedure TForm1.On_App_Exception(Sender: TObject; E: Exception);
begin
  Memo_Error.Clear;
  Memo_Error.Lines.Add(E.message);
end;

end.

//........

object Form1: TForm1
  Left = 224
  Top = 128
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Form1'
  ClientHeight = 154
  ClientWidth = 322
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object MaskEdit1: TMaskEdit
    Left = 8
    Top = 8
    Width = 120
    Height = 21
    EditMask = '!90:00;1;_'
    MaxLength = 5
    TabOrder = 0
    Text = '  :  '
  end
  object Memo_Error: TMemo
    Left = 8
    Top = 40
    Width = 288
    Height = 104
    ReadOnly = True
    TabOrder = 1
  end
end
0
 
LVL 2

Expert Comment

by:DarkCore_
ID: 11712890
In no case an exception should close the program itself automatically.

Most sure something else is wrong, maybe it produces somewhere in your code a stack overflow ( a function which calls itself once and twice without end ). Maybe you've set up an event like onChange or OnExit?

Edu
0
 
LVL 1

Author Comment

by:adamy
ID: 11716941
Why I can't catch the error? There are no errors in my program, but it cannot catch the error.

1. Declare the custom exception handler
{ Public declarations }
procedure MyExceptionHandler(Sender : TObject; E : Exception );

2. Define the exception handler in the "implementation" section:

procedure TForm1.MyExceptionHandler(Sender : TObject; E : Exception );
var
     wRetVal : Word;
begin
     wRetVal := MessageDlg('ERROR: ' + E.Message, mtError, mbAbortRetryIgnore, 0 );
     case wRetVal of
         mrAbort: begin
             { handle "Abort" here... }
         end;
         mrRetry: begin
             { handle "Retry" here... }
         end;
         mrIgnore: begin
             { handle "Ignore" here... }
         end;
         else
         begin
             { handle "other" action here...}
         end;
     end;
end;

3. assign the newly created exception handler

procedure TForm1.FormCreate(Sender: TObject);
begin
     { begin new code }
     Application.OnException:=MyExceptionHandler;
     { end new code }
end;
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:esoftbg
ID: 11718846
example from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21081083.zip
0
 
LVL 3

Accepted Solution

by:
gandalf_the_white earned 30 total points
ID: 11723516
do you mean that the delphi ide pops up and says that there was an exception in your code?

if that is the case than you don't have to worry as this happens only while the program is
started out of the ide. if you start the exe you wont see any exception
0
 
LVL 12

Assisted Solution

by:esoftbg
esoftbg earned 20 total points
ID: 11724103
Hi adamy,
if you don't want to see exception pop-ups under Delphi's IDE, you may suspend them by (Delphi 7):
  - Menu: Tools
    - Submenu: Debugger Options...
      - Tab: Language Exceptions
         - Check box: Stop on Delphi Exceptions - unchecked
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 11818360
the problem with this solution is that you dont get any exceptions in your code anymore

that can be a problem as coding errors may also be hidden from you by delphi.

there are different solutions for this problem.
i like this one the most:

set a breakpoint in the codeline before the exception will happen.
open the breakpoint properties (by rightclicking on it)
there you have the option to show further options (i have german delphi so
i don't know how it is called in english).
down there you have an options that is called ignore further exceptions. check this
and you won't get an exception for the rest of the program. if you uncheck the "hold"
(maybe its called "stop")  option you won't even notice that there is a breakpoint.
after the lines you can set another breakpoint that also doesnt stop and in this one you
check the "treat exceptions" checkbox and in the rest of the program you'll get your
exceptions as you deserve them ;-)

regards
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question