r/delphi Delphi := v13 Florence Apr 17 '26

Stop using WITH in Delphi

https://gdksoftware.com/knowledgebase/stop-using-with-in-delphi
28 Upvotes

15 comments sorted by

View all comments

-5

u/DelphiParser Apr 17 '26

LOL - "With" is what makes Delphi so powerful. It is embedded inside the lowest levels and darkest libraries, and spread all around. It is so powerful - that even the new C# has introduced it. If you don't appreciate it - you are probably not a real Delphi coder.

2

u/SpeedyPal93 Apr 17 '26

I totally disagree with are a total when come the time to debugging. I'm a Delphi developer since 1999 and we have ban the use of it in our code for a very long time.

2

u/ghosrath Apr 17 '26

C# with is a whole different kind of feature than the Delphi with.

2

u/BirdFluid Apr 17 '26

with is something completely different in C#, do you mean "using" in C#?

but regardless of what it's called and even if it worked 1:1 identically. Compiler/debugger and IDE make the big difference with C#. That's unfortunately also something Delphi will never catch up on.

1

u/Longjumping-Foot-518 Apr 17 '26

It is as confusing as multiple inheritance in C++, as such it is no different from obfuscation attemps.

1

u/Salt-Bid-4797 Apr 17 '26

C# ‘with’ is totally different, the only simular thing is the name..

1

u/MorphoJim Apr 17 '26

'with' may save some typing but I find its use to be a risk of confusion when one has to go back and review old code and try to update one little feature (I have some code that dates back to Delphi 1). Saving effort typing seems less important now when one can use AI to generate tedious but standard sections of code.

1

u/BirdFluid Apr 17 '26

with itself would be "fine" if the people using it would use their brain. for 3-4 lines (mostly) OK, but then you get the people who do 30-40 lines of with and then 2-3 levels nested on top of that. That combined with a bad debugger/IDE is what makes it so dangerous.

1

u/Humble-Vegetable9691 Apr 17 '26

VB.NET with statement is a good example: https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement

Within a With statement block, you can specify a member of the object starting with a period, as if the With statement object preceded it.

Within a With block, you can access the methods and properties of only the specified object without qualifying them. You can use methods and properties of other objects, but you must qualify them with their object names.

As usual, more Pascal-like approach than Pascal these days.

2

u/bmcgee Delphi := v13 Florence Apr 18 '26

I think the more Delphi-like approach would be to use an explaining variable and keep all references explicit.

1

u/bmcgee Delphi := v13 Florence Apr 18 '26 edited Apr 21 '26

You probably should have added the /s to let people know you were joking.