菜鸟问:如何解决might not have been initialized问题?(我没分了,见谅)

ldh20042004 2005-01-17 02:21:58
procedure TForm1.ComboBox2Change(Sender: TObject);
var c:integer;
begin
if edit11.Text<>''
then
c:=strtoint(edit11.Text)*strtoint(combobox2.Text);
edit12.Text:=inttostr(c);

end;
错误提示:
[Warning] Unit1.pas(315): Variable 'c' might not have been initialized
==================
我查到了是这个意思:但我还是不知道怎么避免,请教我~~
Variable '<Name>' might not have been initialized 变量名<NAME>可能没有初始化
...全文
6252 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
terry6394 2005-01-17
  • 打赏
  • 举报
回复 1
局部变量要初始化。
ldh20042004 2005-01-17
  • 打赏
  • 举报
回复
谢谢,各位,问题已经解决了,加了begin和end以后。
又学到一招。慢慢来吧。我现在还只懂这么一点,会继续努力的。
szwelcome 2005-01-17
  • 打赏
  • 举报
回复
边缘的对了
Hunto 2005-01-17
  • 打赏
  • 举报
回复 1
如果这样写就不会报错了:
procedure TForm1.ComboBox2Change(Sender: TObject);
var c:integer;
begin
if edit11.Text<>'' then
begin
c:=strtoint(edit11.Text)*strtoint(combobox2.Text);
edit12.Text:=inttostr(c);
end;
end;
terrytzq 2005-01-17
  • 打赏
  • 举报
回复
procedure TForm1.ComboBox2Change(Sender: TObject);
var c:integer;
begin
c:=0;
if edit11.Text<>'' then
c:=strtoint(edit11.Text)*strtoint(combobox2.Text);
edit12.Text:=inttostr(c);

end;
局部变量是要初始化的;
如果if 不满足的化c就没有初始化了,c就是乱七八糟的值.
yytjk 2005-01-17
  • 打赏
  • 举报
回复
在判断语句:if edit11.Text<>'' then后面,加上begin
然后在edit12.Text:=inttostr(c); 后加end

因为你如果不用begin ,end,则只有后面一句是该条件下要执行的
reallike 2005-01-17
  • 打赏
  • 举报
回复
压根就看不懂你写得什么。

先把你的代码风格搞清楚。

这么烂的代码。我不是随便瞧不起别人,

但是,我感觉很不爽……

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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