You may find that some other recordset or object is referenced more often, or that there are just too few references to the "With" object in its block to justify the "With ... End With" block.
Great for eliminating the FeatureEnvy smell that "With" can paper over.
Languages:
In VbClassic: from...
With rsObject .Open ... If .RecordCount = 0 Then .AddNew !PK = value End If !Attr = value End Withto...
rsObject.Open ... If rsObject.RecordCount = 0 Then rsObject.AddNew rsObject!PK = value End If rsObject!Attr = valuePascalLanguage: from...
with emp do begin name := "Joe"; status := "X"; with bday do begin month := 6; day := 27; year := 1958; end endto...
emp.name := "Joe"; emp.status := "X"; emp.bday.month := 6; emp.bday.day := 27; emp.bday.year := 1958;
However
With rsObject .Open ... If .RecordCount = 0 Then .AddNew !PK = value End If !Attr = value End Withis immaculately clear, and prevents a lot of needless typing. This particular example is one in which I would use a WITH construct if my language provided it. Absolutely.
ContributorsList: JeffGrigg, (name of Pascal example author missing)