<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 27 Sep 2012, at 15:51, Marcos Douglas wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">What is the advantages to the compiler return the error bellow?<br>ERROR: unit1.pas(31,3) Error: Duplicate identifier "FooVar"<br><br>Why the compiler do not respect the scope, ie, the local variable<br>should have the preference, I'm not right?<br></span></span></blockquote><div><br></div><div>Yes, but the human brain is very good at confusing such things, and it's very easy to accidentally assign something to a local variable instead of to a field.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">Not? Why I can use a unit name as a property in my class, so? (see<br>bellow the "StdCtrls" property name).<br></span></span></blockquote><div><br></div><div>Because the compiler only checks for identifiers defined in the current unit. You also cannot assign anything to a "unit", nor "read" from it, so there is generally less ambiguity (it still can exist in case the field is a record/class/object and contains fields that have the same name as global variables declared in the unit, but that's not exactly common).</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">If I use {mode delphi} I can compile... I know. Why not in {mode objfpc} too?<br></span></span></blockquote></div><div><br></div><div>Because {$mode objfpc} makes different trade-offs compared to {$mode delphi}. You can pick the one you like best.</div><div><br></div><div><br></div><div>Jonas</div></body></html>