On Feb 5, 2006, at 9:04 PM, Ian R wrote:

This is probably the most basic question ever, but I swear to god I can't get this to work.

Say you create a custom control with the superclass ListBox, call it dbListBox, and there's an instance of dbListBox in ListWindow. And you have multiple instances of ListWindow. And ListWindow has a method called LoadList.

How can I call LoadList from an instance of dbListBox? I had thought I could say "self.LoadList", but it doesn't autocomplete or compile. Doesn't "self" refer to the window the control is in?

Anyway. Can somebody please clear up what I assume is... maybe not the smartest question?

I big subject, so let me just touch on a few points...

When you write a class, you usually want to make it as generic as possible so that you can use it in other projects. So when you write the class, you usually just limit it's influence to the class itself, or possibility subclass derivatives. But when you drag a class or control to the window, this is where you usually implement code specific to the purpose.

For example, a PushButton has properties and one essential purpose... to do "something" when the button is pushed. You could write a PushButton subclass called ClosePushButton to which the only purpose is to close the window it lives on; but this class would be of limited use especially since you can just implement the Action event when you drag the control to the Window.

In the case of Listbox controls, it is not nearly as simple as a PushButton... ListBox controls can have a lot of custom features and behavior styles and it would make sense to make a subclass. But if at all possible, avoid making a subclass which refers to a specific Window, because this subclass is not easily implemented in other projects and other windows. If you follow the model where the ListBox only modifies it's own data/properties (even if they are other subclasses), then you could use the new ListBox control in any project where it would be useful.

Self does refer to the Window when you are implementing events for a ListBox you drag to a Window. When you are working on a subclass, Self and Me refer to the same thing... the object instance.

If you want to refer to the window generically, you can use the Window property of the RectControl (the ListBox super class). This means that you can substitute Window anywhere that you would use Self when you are writing a custom ListBox subclass. This will allow you to modify or get any of the standard window properties... but if you want to access another control or a method in a specific window, then this technique will not work. This is because when you create a new window, it is like you are really creating a new subclass of type Window.

That is all that I have time for right now, so let me (or the list) know if you need to access a specific window and then we can explain it.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to