I can pass a parameter to a subclassed thread’s Constructor byRef, but then it has to be saved to a property of the subclass, at which point it’s no longer byRef.
I’m currently using the ugly workaround of passing an array of which I use only the 0th element, but I feel there should be something more elegant using a MemoryBlock or Ptr or some such, which I don’t know how to do.
If you have a parameter of type “ptr” in the threads constructor you can simply pass a property of type MemoryBlock to it. The thread stores the pointer in an own property of type “ptr” and you can use that in the Run event. All you write via the pointer goes directly in the MemoryBlock you assigned. You simply have to make sure that the MemoryBlock don’t go out of scope as long as the thread runs.
I tried following your recommended setup, but the passed variable in the calling routine is not modified by the thread. Assuming it can be made to work, while possibly “purer”, it ends up being slightly more opaque and verbose than what I’m doing now, so maybe I’ll stick with it as Kem suggests.
I think your current solution is the best / only way if you want the thread to manipulate that exact value. An alternative would be to wrap the data inside a class instance. I did log an enhancement a few years back (53332) to allow a variable to point to another variable which probably would have worked for you.
An alternative approach would be for the thread to have its own copy of the data and to raise a custom event with the new value when it changed.