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.
Related
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?
I have a hieraarchy of classes. Root class is abstract, and is called Contact, and it has a property DisplayName. On GUI I have a dropdown where various contacts are listed, using their DisplayName property.
I have no acess to source code of those classes.
I want to somehow override Contact.DisplayName property, to make it display something else in my particular scenario. I can not just create subclass of Contact and override property there, because there is whole hierarchy under Contact class. Is there a way to alter a property for whole hierarchy of classes ? Maybe using delegates ?
I am using exotic programming language called Gosu, but the solution based on some common object oriented language could help me a lot too.
I haven't tried but maybe with Enhancements. I'm not sure that it works because DisplayName it's a property of entities.
Update:
There is a folder in Guidewire Studio, configuration/config/Entity Names. Open Contact.en and there is you can customize the DisplayName.
Can you type cast the Contact entity to its subtype and try to display it in GUI. Something like (Contact as Person).DisplayName
It's come up several times that I have wanted to access a property of a component which is bound to another property. I've spent days trying to figure out how to do this and failed. Below is a simple example of what I'm trying to do.
TabView {
Component.onCompleted: console.log(style.frameOverlap)
// OR tvStyle.frameOverlap
style: TabViewStyle {
id: tvStyle
frameOverlap: 5
}
}
Nothing like this works. I'm completely baffled about how to access these members either statically or as an instance. Can someone please explain to me whether something like this is possible?
Thanks.
The short answer is that you need to write:
Component.onCompleted: console.log(__styleItem.frameOverlap)
The longer answer is that the 'style' property is a Component. Component is something that remembers a tree of declarations, and can create objects as needed. However, it does not expose that remembered declaration, so when you try to access the frameOverlap property, it's not there.
In theory, you can call style.createObject to create an object, and examine its properties, but that would create another unnecessary instance, so you can look at TabView.qml, notice that it creates an instance already using Loader, and stores that in a property called __styleItem, and so use the code I gave above.
Of course, accessing internal properties is not a particularly good idea, but might be OK in practice. Ideally, one should be able to instantiate TabViewStyle and bind the instance to the style property, with TabView figuring out whether it's Component or object, but I'm not sure it's possible.
Say I have a class TestClass with the following definition:
Option Explicit
Public x As Variant
I want an instance of this class to be created when the workbook opens, and usable in other workbook events. So in the ThisWorkbook module, I add:
Public tc As TestClass
Private Sub Workbook_Open()
Set tc = New TestClass
tc.x = "abc"
End Sub
When I compile this, I get an error:
Private object modules cannot be used in public object modules as
parameters or returns types for public procedures, as public data
members, or as fields of public user defined types
I was able to resolve this by going to the Properties Window for TestClass and setting Instancing to PublicNotCreatable. It seems that this hasn't affected the behavior of the class or my ability to create local instances of it within various functions in this VBA project. Does changing this Instancing setting have any potential problems?
PublicNotCreatable is so you can use that class in a different VBProject. The NotCreatable part means that whatever VBProject hosts the class has to create any new instances and pass those to the other VBProject. The other VBProject cannot create them by itself.
What you want to do is Public tc As TestClass in a standard module and keep your class instancing Private. Declaring a variable public in a standard module makes that variable available everywhere in your project.
What you did is created a custom property of the ThisWorkbook instance of the Workbook object. ThisWorkbook is a class module (so are the sheet modules and userforms). Those class modules are special because they have a user interface component (workbooks, worksheets, and forms), but they're class modules all the same. You can define properties and methods in ThisWorkbook just like you do in a custom class. And that's what you did. You created a custom property called tc.
To create a property in a class, you can either use Property Get/Let or Public. The shortcut of using Public looks a lot like declaring a public variable in a standard module, but it's not quite the same.
So why the error? When your custom class instance is a property of another class, VBA won't let you create an instance of the custom class because you could end up with a child class and no parent class.
So keep your instancing private and declare your public variables in a standard module. I have a special module called MGlobals where I keep all my public variables. If I have more than a couple, I'm probably doing something wrong.
I am new in Yii. And some things in this framework i am understand well. But i am can't understand how work Yii::app() and where i can find Yii::app()->user->checkAccess method?
Should you are explain me it. Thanks!
Yii::app()->user is the user component, which is defined in your config file (usually /protected/config/main.php). In the components array you will find a 'user' component. The default class for this is CWebUser, so probably 'checkAccess' is defined in CWebUser (did not check this though).
You can write your own class extending CWebUser if you want to override this property (it's not a method).
See your /protected/config/main.php file, and then you may find authManager section in components. In my case, I set the class of authManager to CDbAuthManager. In that class, checkAccess method is defined.