The dreaded with…

The dreaded with…

Debugging today, I found another gotcha.

In this case, both Self and DisconnectedClient has a property named ClientIdentifier.

Note the difference for the mouse-over and the evaluation.

12 thoughts on “The dreaded with…


  1. This is one reason why my company (and I^^) dont allow the usage of with 😉


    With (ahaha^^) great power comes great responsibility


  2. With can be used responsibly, as in:


    with AnObj do


      Prop1 := MyVal;


      Prop2 := SomeValue;


      Prop3 := SomeOtherValue;


    end;


    Where usage becomes evil is when the with clause contains more than a few lines of simple code, or when it specifies multiple objects. In the latter case, it is as difficult and dangerous as multiple inheritance.


    Given that it is always an alternative to declare a local variable of the desired type, with a short name, and thereby gain the benefits of with, while encountering none of its ugly aspects, that is generally preferable.


  3. Asbjørn Heid – The type is implied in my suggestion – and you could cast the right side if you needed to.  Another point is that this limits the scope to just the with clause.

Leave a Reply