Why is the Compiler warning that variable may not be initialized?

丶灬走出姿态 提交于 2019-11-29 14:34:10

Var1 will always be initialised before it is used. The compiler gets confused by try-except handling: your code is too complex for the compiler to be able to actually determine that Var1 is always initialised. It sees there may be a handled exception before Var1:=6;, which would leave Var1 uninitialised, but it doesn't see that that exception will always be re-raised.

You should but the ShowMessage(IntToStr(Var1)); into the try except block. Then it should be clear to the compiler, that Var1 is intialized and looks more as clean code.

It is a farily good warning. What it tells that you do not assign any value to the variable which may be used somewhere else in your code. Warning also tells that if it's used then the value assigned to it may be not what you expect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!