home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / EXCEPT3 / MAIN2.PAS < prev   
Pascal/Delphi Source File  |  1995-09-02  |  993b  |  57 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     Label1: TLabel;
  12.     Edit1: TEdit;
  13.     Label2: TLabel;
  14.     Button1: TButton;
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   MainForm: TMainForm;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TMainForm.Button1Click(Sender: TObject);
  30. var
  31.   N: Integer;
  32.  
  33.   function GetInteger: Integer;
  34.   begin
  35.     Result := StrToInt(Edit1.Text);
  36.     if (Result < 0) or (Result > 99) then
  37.       raise ERangeError.Create('Value out of range!')
  38.     else begin
  39.       ShowMessage('Success! Click Ok to end program');
  40.       Close;
  41.     end;
  42.   end;
  43.  
  44. begin
  45.   try
  46.     N := GetInteger;
  47.   except
  48.     on E: Exception do
  49.     begin
  50.       ShowMessage(E.Message + ' Try again.');
  51.       Edit1.SetFocus;
  52.     end;
  53.   end;
  54. end;
  55.  
  56. end.
  57.