Well yes, as it turns out (I tried it too). But that was a cut-down example with just the bits that make it funny. For some reason, in the real, more complex example it does not manage to work that out for the warning, but does manage for the hint.
Samuel -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Brennan Sent: Tuesday, June 01 2004 11:37 a.m. To: NZ Borland Developers Group - Delphi List Subject: RE: [DUG] Weird Delphi Warning Sam, I don't get a warning on the first example. The compiler is smart enough to work out that 'bob' will always be initialised because there is no way out of the if/else statement without either assigning to bob or raising an error. I do get a hint on the second example and again this is how it should behave. In general it is always possible to eliminate hints and warnings. Sometimes it requires an initialisation line that isn't strictly required (generally because there are multiple if statements and the compiler can't determine the exact program flow) but it is always possible. David. > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Allan, Samuel > Sent: Tuesday, 1 June 2004 11:07 AM > To: NZ Borland Developers Group - Delphi List > Subject: RE: [DUG] Weird Delphi Warning > > > I've got another one that I found funny: > > procedure Samuel([arguments]); > var > bob: Integer; > begin > ... > if [condition1] then > bob := 1 > else if [condition2] then > bob := 2 > else if [condition3] then > bob := 3 > else > raise Exception.Create('error message'); > jim := bob + 10; > ... > end; > > gives the warning "Variable 'bob' might not have been initialized" on > the line "jim := bob + 10". Which is true, even though if bob has no > value then the exception will prevent that line of code from being run. > But, if you change the code to: > > procedure Samuel([arguments]); > var > bob: Integer; > begin > ... > bob := 0; // added this line to get rid of warning > if [condition1] then > bob := 1 > else if [condition2] then > bob := 2 > else if [condition3] then > bob := 3 > else > raise Exception.Create('error message'); > jim := bob + 10; > ... > end; > > then you get a hint "Value assigned to 'bob' never used". > > _______________________________________________ > Delphi mailing list > [EMAIL PROTECTED] > http://ns3.123.co.nz/mailman/listinfo/delphi > _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
