Xojo: Any way to assign the reference to a ByRef parameter to a property?

I don’t think what I want to do is possible in Xojo, but thought I’d check with experts here to make sure.

I want to pass a variable (usually a string or number) ByRef to a class, let that class do some UI stuff with the user which modifies the value, and have the change automatically reflected in the calling method’s scope. The problem is, the ByRef “link” is constrained to the called method’s scope - I can’t find any way to “assign” that reference to a class property so it can be used by other methods in the class and still have changes to the value affect the original value.

The purpose of this need is to avoid using the usual “raise event/react to event” paradigm for sending a value to a UI object and getting any change to the value back.

Any ideas?

don’t you mean “pass a variable ByRef to a METHOD in a class”?

If I’ve understood you correctly, you would have to store your data in a dictionary or class and pass that around.

This enhancement request would probably have helped:


ah you want the CLASS instance to retain a reference to the variable passed ?

Because Xojo intrinsics are value types the ONLY place you get a reference is in the method called and there is no way to retain a reference

The easiest way I can think of for you to retain a REFERENCE is to use use a class that wraps the intrinsic (Java does this with String wrapping a string)
Then you could retain a reference to it
And you wouldnt need to pass it in BYREF

Are you talking something like this?

I’ve read that before, and I had thought about using an interface, but didn’t think it would work the way I wanted. But re-reading that article (and the following one) gave me some ideas. In short, I will pass (a reference to) the calling object as a parameter and have the called object update the value in the calling object using a method defined in an interface. So not a “notify all objects” but directly on this specific one, and without having to use introspection.

Thanks everyone.

Introspection does let you do some … fun things :slight_smile: