Solved

How to stop MaskEdit exception?

Posted on 2004-08-03
7
2,773 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reconfigure Delphi Install? 2 64
select query - oracle 16 101
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 146
Wincontrol not (correctly) drawn 15 47
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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