Infamous WITH resolution

We all know that the WITH statement available in Delphi. A lot people cry that it’s evil and you should not use it. From my point of view using with is only reasonable for a single line or maybe just few lines of code in begin end block. Why is WITH bad? The main problem is the name space collision and the thing when you have big code sections in WITH block – you can make mistakes just because of the WITH and identifier name match.

There is one of the top voted report in Quality Central about “The infamous WITH resolution“.

Personally I dream about solution for the WITH like following:

with Long.Identifier.Name.OtherField as A, Other.Long.Field.Access as B do
    A.Value := B.Value;
    B.Value := 'Something other';

Of course as somehow conflicts with AS operator, but the idea is clear. Maybe it can be some other reserved word..

If such thing is done that will be a new life for the WITH statement.


  1. Why you don’t refactor such code in a own method?

    doThings( Long.Identifier.Name.OtherField, Other.Long.Field.Access);

    procedure doThings(const a:TFoo; const b: TBar);
    A.Value := b.Value;
    B.Value := ‘Something


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s