April 29, 2024, 07:22:05 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


OOP Question

Started by Bruce Peaslee, April 19, 2007, 11:28:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

I have a dialog with a list view control. One of the items (lines) is selected. When the user picks a menu item, a second, child dialog opens to allow the user to change aspects of the item in the list view. I know that we can edit in place and I know that I can send info to the second dialog's class methods to identify the selected item.

The question I have is this: can I reference the parent window of my second dialog - from the second dialog - in such a way as "see" which item in its list view is selected?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

J B Wood (Zumwalt)

In the parent class, make a shared static variable, this variable you update when ever an item is selected in the parent class, then in the child class, you reference the parent class shared static variable to retrieve its contents.

You could tighten this down some and make a private variable in the parent class that holds this value, then make a getter method that retrieves this value, the getter would be public static, so then the child could call this public static method without you having to make an instance of the parent class.

Let me know if this makes sense.

Bruce Peaslee

April 19, 2007, 03:11:17 PM #2 Last Edit: April 19, 2007, 09:47:10 PM by peaslee
Quoteauthor=Jonathan (zumwalt)
Let me know if this makes sense.

It does, but I don't know how to code it. How do you reference a variable in a parent class?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

J B Wood (Zumwalt)

April 20, 2007, 07:25:41 AM #3 Last Edit: April 20, 2007, 07:37:05 AM by Jonathan (zumwalt) Wood
Ok, this is not the easiest thing to explain with Aurora so please bear with me, its more of an intermediate programming skill to do it.
First, Aurora doesn't support Static methods directly (if it does, or static variables, Paul please explain how)
Here is the chain of events to make this work.
1) create a class that will be used as a member object to your base class, in my project that is attached, I called this class myGlobal
2) in this class, you will store your variable (or object) that you want to share amongst other classes attached to your base
3) attach you base include to your global include and include an object that instansiates your global class in your base class, I did this in my base class include by created a myGlobal test object.
4) in your base class, create a method that will display the results of the global variable, which we will later set in our parent class, I did this by creating a declare showValue in my base class
5) in your parent class, inherit your base class
6) in your parent class in one of your methods set the value of the global object, I did this as test.myValue=12 in my parent object
You have now filed the global variable that is available to your base class.

Sounds like alot of work, but its really not, just alot of forward thinking.
Now in my global main, I can see the result by calling the value through the base showValue method, which I did in my main.
Let me know if I need to break this down even more with inline instructions in the code.
Attached is a zip of the full project and all files, delete the files you don't need for recompiling etc.

DO NOT instansiate the variable or try to use the variable in your base class constructor!
The way class chains work in aurora for base class to parent class (and in all OOP really), is that the base class gets created after the parent class default constructor gets created, so if your parent class constructor sets the global variable, the global variable will not be created until the base class is finished. Kind of confusing, but look at how that project is setup and read through each class and its includes to see who is calling what and when.