As have been mentioned by several people in several places (newsgroups, blogs, QC etc.) Delphi's with-statements can be harmful to the readability, maintainability and robustness of your code. Not to mention it makes debugging harder ;).
Much like the problem with potential duplicate identifiers from used unit scopes, the with-statement problem could be mitigated by enhancing the compiler to produce Warnings for ambiguous with-statements.
Consider the following code:
Unit Foo;
type
TGadget = class
bar: integer;
end;
Unit Bar;
var
a: TGadget;
foo: integer
begin
with a do
foo := 123;
end;
This is version 1. Code compiles without warnings and works correctly. Now Mr. Component on the other side of the globe makes an update to the TGadget class:
Unit Foo;
type
TGadget = class
foo: integer;
bar: integer;
end;
Then John Doe recompiles his code with this new version:
Unit Bar;
var
a: TGadget;
foo: integer
begin
with a do
foo := 123;
end;
Currently, with D7, there is no warning. Code compiles, but it fails mysteriously at run-time. In a future version of the compiler he could get warning such as: Warning: Potential name conflict: foo declared in unit Bar and Foo.TGadget. In this case, to get rid of the warning, the programmer could change the code to
Bar.foo := 123;
or (even better) he could just get rid of the with-statement.
IMO, if we could have this kind of warning for with-statements, it would be the first steps towards patching one of the very few sorespots of the otherwise elegant Object Pascal language. (and before you ask, yes, this has been QC'ed: #8770).