Solved

How to stop MaskEdit exception?

Posted on 2004-08-03
7
2,669 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

12 Experts available now in Live!

Get 1:1 Help Now