关于异常 谁有自定义异常的实例代码?多谢,一经试用成功,就给分。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations }end;varForm1: TForm1;type eageexception=class(exception)public data:integer; constructor create(const msg:string;age:integer);end;implementation{$R *.dfm}constructor eageexception.create;begin inherited create(msg); data:=age;end;procedure TForm1.Button1Click(Sender: TObject);varage:integer;begin try age:=strtoint(edit1.Text ); if (age<=0) or (age>108) then raise eageexception.create('输入的年龄无效',age); except on ex:eageexception do showmessage('年龄为'+inttostr(ex.data )+',视为无效'); on econverterror do showmessage('年龄应为整数'); end;end;end. 感谢ctd(☆常想一二☆),给分! 一个弱弱的问题,请教了 多个caption变化问题 同一个事件,如何控制其是否可用? 关于菜单设计的问题:为什么我没有定义快捷键却显示了一个快捷键 线程 请问我想让dbgrid控件的第一列可以实现下拉框,以选择类型,如何实现? 如何打开GIF动画,并根据画面在屏幕上重绘点阵?求高手! Object Pascal中constructor是如何被调用的? 请问哪位师兄有收发电子邮件的程序(含源码)? Ole自动控制对象的简单问题。 delphi7怎么没有报表控件栏? 如何编写通过代理服务器发送邮件?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;type
eageexception=class(exception)
public
data:integer;
constructor create(const msg:string;age:integer);
end;implementation{$R *.dfm}constructor eageexception.create;
begin
inherited create(msg);
data:=age;
end;procedure TForm1.Button1Click(Sender: TObject);
var
age:integer;
begin
try
age:=strtoint(edit1.Text );
if (age<=0) or (age>108) then
raise eageexception.create('输入的年龄无效',age);
except
on ex:eageexception do
showmessage('年龄为'+inttostr(ex.data )+',视为无效');
on econverterror do
showmessage('年龄应为整数');
end;
end;end.