Scope/Function names and labels: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 161:
If you are trying to figure out what happened, you now understand goto.
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
1. Delphi is a one pass compiler, so the names of procedures, functions, variables, constants and types are only visible to code that comes after the item was declared. Procedure and functions can be "Forward" declared, which allows them to be declared before they are defined.
 
2. All items inside an object are visible throughout the object, no matter the order they are defined. Outside an object, the object and items inside it are only visible to code that comes after it was declared.
 
3. Delphi prodedures and functions can be nested. Varibles inside a procedure or function are only visible from inside the same procedures or functions. Variable, procedures and functions at higher levels of nesting are visible to lower levels of nesting.
 
4. Items inside objects have controlled visibility to the outside world. Objects are divided in specific sections that control the visibility of items inside the section. Here is a list of sections:
 
Private: Items contained within the "Private" section of an object are only visible inside the object.
 
Protected: Item contained within the "Protected" section of an object are only visible inside the object or inside object that inherit from the object.
 
Public: Item contained within the "Public" section of an object are completely visible to the outside world.
 
Published: Item contained within the "Published" section of an object are visible to the outside world and can be manipulated by the IDE.
 
 
<syntaxhighlight lang="Delphi">
 
// Test1 is visible to Test2, but not vice versa.
// The local variables A, B, and C invisible to the outside world.
 
procedure Test1;
var A,B,C: integer;
begin
end;
 
procedure Test2;
var A,B,C: integer;
begin
end;
 
 
// Test1 is visible to all code that follows it.
// Test2 is invisible to the ouside world
 
procedure Test1;
var A,B,C: integer;
 
procedure Test2;
var A,B,C: integer;
begin
end;
 
begin
end;
 
 
// Item1 and Test1 are only visible inside the object
// Item2 and Test2 are additional to inhered objects
// Item3 and Test3 are visible to the outside world
// Item4 is visible to the outside world and the IDE
 
 
type TMyObject = class(TObject)
private
Item1: integer
procedure Test1;
protected
Item2: integer
procedure Test2;
public
Item3: integer
procedure Test3;
published
property Item4: integer read FItem4 write FItem4;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
 
</pre>
 
 
=={{header|Eiffel}}==
465

edits