Hello all,
Is there an equivalent of Using or With? I have a series of object that all within a container, but rather than type the container “name.” each time I wanted to do a
Using MyContainer
.Var1
.Var2
.Var3
End Using
Thanks,
Tim
Hello all,
Is there an equivalent of Using or With? I have a series of object that all within a container, but rather than type the container “name.” each time I wanted to do a
Using MyContainer
.Var1
.Var2
.Var3
End Using
Thanks,
Tim
There is not.
There is, however, a search function on the forum.
You can also search using Google with a query like site:forum.xojo.com using statement
If you find yourself doing that a lot within code, then the procedure (method) probably belongs within the container where such reference would not be necessary.
This topic on the pros/cons of “WITH/END WITH” has occurred at various time on this forum… With a lot of people against it, and some (like myself) who believe it would (can) be a good structure… Especially since it is one that has the benefit of being used or not used at the discretion of the developer with no negative impact on the final product.
Actually, the new framework brought about Using with
Using Xojo.Core
It maybe time to fill a feature request based on the fact that it is already here.
But Xojos Using is about the framework, not a class instance.
However: Like Roger said, complicated references could be avoided by making the method a part of the container class. From inside, its only a
me.Var 1 = xxx
me.Var2 =
etc.
An example is a sales order or an invoice, where price calculation and automatic account assignment depend on material and customer attributes (properties). I worked around the issue by duplicating customer properties and material properties relevant to pricing calculation and automatic account assignment into the document class and document item class. There is a method in the sales partner class and in the material class to populate such document properties. Then, the document properties are referenced. It is a duplication of information, but it reduces the complexity of the code.
Or simply a local variable if the reasoning is that the base expression is complex.
Class ContainerControl1 Inherits ContainerControl
Public Function aMethod() As String
Return “OK”
End Function
Control PushButton1 As PushButton
// Define the control
End Control
Control PushButton2 As PushButton
// Define the control
End Control
End Class
Class Window1 Inherits Window
Control ContainerControl1_v1 As ContainerControl1
// Define the control
End Control
Control PushButton1 As PushButton
Sub Action()?
Dim c1 As ContainerControl1 = ContainerControl1_v1 // From now on you can write less
MsgBox c1.aMethod // < c1.aMethod instead of ContainerControl1_v1.aMethod
End Sub
End Control
End Class
[quote=282162:@Tim Parnell]There is, however, a search function on the forum.
You can also search using Google with a query like site:forum.xojo.com using statement
:)[/quote]
Search results are generally terrible for most forums, including here. That google search results in only one useful thread on this topic, which is actually THIS thread.
Interestingly “With” is a reserved word in Xojo.