奇事都被我碰到,快点帮我。

ItOldHorse 2003-08-22 06:09:12

for i:=6 to 26 do
begin
sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
end;

这一句可以执行,但下句为什么不能执行呢?


for i:=40 to 48 do
begin
sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
end;
...全文
31 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ItOldHorse 2003-08-22
  • 打赏
  • 举报
回复
此题至今无人解答!!!
qianguob 2003-08-22
  • 打赏
  • 举报
回复
同意楼上的。
huojiehai 2003-08-22
  • 打赏
  • 举报
回复
var
Comp: TComponent;
for i:=40 to 48 do
begin
Comp := findcomponent('e'+inttostr(i));
if Assigned(Comp) then
if Comp is TEdit then
try
sum:=sum+strtoint(Tedit(Comp).Text);
except
showmessage(Tedit(Comp).Text + '不是整数');
end;
end;
ItOldHorse 2003-08-22
  • 打赏
  • 举报
回复
showmessage('40 '+e40.Text);
showmessage('41 '+e41.Text);
showmessage('42 '+e42.Text);

这三句均可执行为什么下句不能执行?

for i:=40 to 42 do
begin
if findcomponent('e'+inttostr(i)) is TEdit then
sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
end;
DWGZ 2003-08-22
  • 打赏
  • 举报
回复
for i:=40 to 48 do
begin
if FindCompnent('E' + IntToStr(I)) <> nil then
sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
end;
huojiehai 2003-08-22
  • 打赏
  • 举报
回复
前面的找到,后面的没找到当然会出错啦,你的写法不对,正确写法是这样的

for i:=6 to 26 do
begin
if findcomponent('e'+inttostr(i)) is TEdit then
sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
end;

for i:=40 to 48 do
begin
if findcomponent('e'+inttostr(i)) is TEdit then
sum:=sum+strtoint(Tedit(findcomponent('e'+inttostr(i))).Text);
end;
hkbarton 2003-08-22
  • 打赏
  • 举报
回复
完全同意
GreenWaterBlueSky 2003-08-22
  • 打赏
  • 举报
回复
你确定是否有40多个组件?
建议用
try……except……end;结构,免得异常没有处理

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧