The added line should not be necessary (under Delphi 5 anyway) to avoid warnings.
It almost sounds like you guys have a different version of the compiler. David. > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Allan, Samuel > Sent: Tuesday, 1 June 2004 11:41 AM > To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List > Subject: RE: [DUG] Weird Delphi Warning > > > Hey, it works. Thanks. > > Also, forgot to add: in version two (of mine), the compiler also > optimises out the "bob := 0;" line. > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Leigh Wanstead > Sent: Tuesday, June 01 2004 11:27 a.m. > To: NZ Borland Developers Group - Delphi List > Subject: RE: [DUG] Weird Delphi Warning > > > How about this? > > 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 > begin > raise Exception.Create('error message'); > bob := 0; // added this line to get rid of warning > end; > jim := bob + 10; > ... > end; > > Leigh > http://www.salenz.com > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Allan, Samuel > Sent: Tuesday, June 01, 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 > _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
