>It seems that since Delphi2005 was released, you can declare constants and
types within the body of a class's interface >declaration.
>...
>The question is, why would you want to use this style of declaration, and
what are the benefits/pitfalls of doing so?
C# uses this principle (as does Java). I switched to C# and after using the
Delphi 'method' for a long time it took some getting used to. The idea is
to declare variables at a much tighter level of scope. This means that if
you do something like this in c#:
int i = 0;
for (int i; i<10;i++) {
WriteLine("\tinside: " + i.ToString());
}
WriteLine("outside: " + i.ToString());
Will give you:
inside: 0
inside: 1
inside: 2
inside: 3
inside: 4
inside: 5
inside: 6
inside: 7
inside: 8
inside: 9
outside: 0
The main 'benefits' I've found are
1) much tighter control of scope.
2) declare as you need a variable
The obvious 'disadvantages' are
1) lack of forward planning
2) more difficult to read and debug code (though dynamic debugging the
application is sometimes easier)
Regards
John
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi