Invoke function whenever any property of an object is changed in Kotlin - kotlin

I want a function onAnyChange() be called whenever any property of an object is changed. Ways to do this would be
Define a setter for each property and call onAnyChange() in each
Define one function that takes a property name as argument, sets the property via reflection and calls onAnyChange(). Use only this function to change properties.
Is there a more convenient way to do this?
Seems to be possible e.g. in JavaScript: How do I invoke a function whenever a property of an object is read?

Related

Overload pyqtProperty

I have a custom widget which I'm using in a QWizard. It has a property called path, which can be a Path object (from pathlib), or None. I implemented this as a plain python property, but I need to change it to a pyqtProperty so I can use it as a field in the wizard.
Is it possible to overload the property so that it can work with None as well as Path?

Are variable in aurelia custom attributes "static"

Say I have a custom attribute in Aurelia and I put it on two different element.
If I have variable defined in the class called clickWhen: Date;
And if I set that in a method fired from the first element that has the custom attribute (ie `setupDoubleClick).
If a method is fired from the second element that has the custom attribute on it, is this.clickWhen set (because the first instance has set this.clickWhen) or is it still undefined.
(I hope it is the second.)
They are separate instances and they won't affect each other.

Change attribute/getter/setter visibility in abap persistent class

Is there a possibility to change the visibility of the setter/getter from an attribute without changing attribute visibility?
e.g in Java I can say:
attribute: private
setter: protected
getter: public
That is very practic if I want to allow only in private scope changes, in protected scope I allow changes via setter (some checks and verifications in there) and in public scope you can only read.
In the classbuilder you can only change all of them together.
You can make the attribute public and change it to read-only in the persistence mapping - this will prevent the setter from being generated. You can change the attribute visibility in the class builder or the persistence mapping, which will affect both the setter and the getter. As far as I know, there are no other ways to affect the visibility. For a greater control, I'd recommend wrapping the persistence class - either in a separate class or by introducing a public getter-only interface whose methods defer to the generated getters.
Yes, it is possible. Just make use of this button.
And then change the visibility

Changing a oneway bound TextBlock value from code behind.

I have a TextBlock and its Text property is bound to a ViewModel property. The binding is Oneway.
When I change the Text property of the Control from the xaml.cs the binding gets broken. If the binding is TwoWay I don't have this problem but the source property is updated too. Is it possible to have OneWay binding and change the target property value without braking the binding?
I suggest a workaround, like setting the Binding to TwoWay and ignore the update in the property. Something like this:
private string textValue;
public string TextValue
{
get { return textValue; }
set
{
:
}
}
Now the Property can no longer be set by the view.
Although no code is provided, this scenario typically occurs when you have bound a control to a view model and at a later stage your logic tries to update the value in the control programmatically.
You should not try to do this, that is define multiple sources of the value for a control. If you bind the control to a property on the view model, then to update the value in the control you should update the field in the view model.
If you were to set the value of a bound control programmatically at runtime so that it no longer matched the bound object value, when some other event causes the control binding to be re-evaluated, the value that you have provided programmatically would be overwritten again, you could easily end up with a scenario where the value you provided programmatically is never visible to the user.
In this scenario you should either:
Add a new property to the view model, bind this value to the control, then your program logic can set this value equal to the original property when the data is loaded, and updated when you need to
Not use bindings at all, always write to the control programatically that way you tightly control when the value is updated.
There is a workaround to this if you absolutely must have one. if you are using compiled bindings (x:Bind), then because the bindings are compiled it is possible to call SetValue on the bound dependency property at runtime and the previously compiled bindings will still be evaluated. However I advise against exploiting this because it makes your code a lot harder to follow and debug, when bindings are used, we tend not to look for code that directly addresses and sets control values.

Can't access methods from another class - VB

Example ^. I must be forgetting something or being really dumb.
You're accessing from the class, not the object, that's why only class methods get shown. Create inbox object first and use that to call the instance method.
Yep. You're referencing the class, not the object.
inbox = new Inbox()
inbox.getEmail()
create an object of Inbox class and then access it. If you want to access with Class name then you need to make the access member static.