我在界面上放了n個edit輸入空間edit1,edit2.....editn
我要取的所有輸入框中輸入的整數的和
能不能用一個for 語句﹐邊判斷輸入是否合法﹐邊累加值?
a: array of TRzEdit;
for i:=0 to n do
begin
try
strtoint(a[i]);
count:=count+strtoint(a[i].text);
except
showmessage('輸入不時整數');
end;
end這樣好象不行﹐應該怎么做?
我要取的所有輸入框中輸入的整數的和
能不能用一個for 語句﹐邊判斷輸入是否合法﹐邊累加值?
a: array of TRzEdit;
for i:=0 to n do
begin
try
strtoint(a[i]);
count:=count+strtoint(a[i].text);
except
showmessage('輸入不時整數');
end;
end這樣好象不行﹐應該怎么做?
解决方案 »
- 根据memo控件的项数 如何实现union联合查询?
- delphi 中如何在form1窗口中添加一个方法,并且怎样在类中调用自身的方法呢?
- 在fastreport中如何设置字体颜色、粗体、正常及下划线?
- 编译出现错误:“9991 2707 Unknown table type.”
- TdxDBMaskEdit如何在Enable:=False;時改變背景顏色?
- 如何在关于窗体上点击主页或mall,就自动打开ie或outlook连接
- 关于在向固定格式的Word模版中导入数据的问题,急!!!!!!!!!!!!!!!
- 菜鸟求救:我在Sql server中有个datetime字段,本来有时间的,在程序中怎样把它置空
- 资源文件的使用一例求助???
- 关于网卡?
- 关于系统时间的修改的问题,可能很少有人考虑过
- 苦恼,socket server问题
i: integer;
total: integer;
begin
total:= 0;
for i:= 1 to n do
begin
total:= total+ strtoint(TEdit(FindComponent('Edit'+inttostr(i))).Text);
end;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8]) then key:=#0;
end;还有既然放控件了,就不要在定义控件数组了。
i: integer;
total: integer;
begin
total:= 0;
for i:= 1 to n do
begin
total:= total+ strtoint(TEdit(FindComponent('Edit'+inttostr(i))).Text);
end;
end;
var
i,Count:integer;
begin
Count := 0;
for i:=0 to Components.ComponentCount - 1 do
begin
if Components[i] is TEdit then
begin
Count := Count + StrToInt(TEdit(Components[i]).text);
end;
end;
Showmessage(IntToStr(Count));
end;