|
-
Feb 1st, 2013, 02:30 AM
#1
Thread Starter
Junior Member
Inheriting Object from parent form
Hi,
I have a main form and I also have an additional form that is loaded from the main form. I would like to reuse an object that is declared and initialized in the main form. How can I do this? I set the child form to inherit from the main form but when I try to use the object, I receive errors indicating that it has not been declared.
Here is an example of what I have:
Code:
public class Mainform
dim myObject as theObject = nothing
myObject = ctype(function(),theObject)
End class
public class Childform inherits Mainform
myObject.function()
End class
-
Feb 1st, 2013, 02:58 AM
#2
Re: Inheriting Object from parent form
You don't inherit objects. You inherit members. If ChildForm inherits MainForm then it will inherit all the properties, methods, events, etc. of MainForm. That doesn't mean that creating an instance of MainForm and an instance of ChildForm will magically give the ChildForm instance access to the data from the MainForm instance though. Both objects will have the same members but those members will have different values.
This is not a job for inheritance at all. It's purely and simply a case of passing data from one object to another. The MainForm instance creates an instance of ChildForm and passes to that instance the appropriate data, either by setting a property or by calling a method and passing an argument. It's just like creating a Button and setting its Text property. That's how you pass data into an object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|