In VB.NET I can use the With keyword if I need to set various properties on the same object, such as below:
With MyControl
.Left = 0
.Top = 0
.Value = "Hello World!"
End With
Does an equivalent exist in Xojo?
In VB.NET I can use the With keyword if I need to set various properties on the same object, such as below:
With MyControl
.Left = 0
.Top = 0
.Value = "Hello World!"
End With
Does an equivalent exist in Xojo?
No. The closest you can come is something like this:
var c as MyControlType = MyControl
c.Left = 0
c.Top = 0
c.Value = "Helo World!"
That’s not quite the same, but at least it minimized typing.
Wouldn’t there be a slight performance penalty taking this approach? I would assume it is creating a pointer to the original object and not a copy, but that pointer still needs to be resolved when it’s referred to.
If there is, I can’t imagine anyone could tell the difference.
Delphi has a similar type of construct. Among the many developers I work with its usage is frowned upon due to potential code ambiguity or unintended consequences when they are nested.
True it may save a few keystrokes but with code completion it hardly seems worth the compromises.
I’m in the habit of using very descriptive variable names - think “orderedPageObjectConfigurations”, for example, and then while looping through them “currentPageObjectConfiguration”. This helps me remember the class of each variable and “current” indicates that it is the target of the loop.
This is great for memory but as you can imagine that the code can get very wordy, especially if I’m assigning several properties of the current object. It’s not a high priority for me but I would welcome the With structure.
Personally I would never use it.