Solved

How to stop MaskEdit exception?

Posted on 2004-08-03
7
2,691 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now