473,659 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing parent properties

Leading on from a recent topic, "How does child class access parent's
variables", I would like to ask, what's the most elegant way of
changing a parent/grandparent/great-grandparent's property?

The class Nest has a subclass SubNest. Within SubNest I want to work
with Title. I think if I can pass Title ByRef to the children and
grandchildren, it would work, but VB doesn't do so by default, and
indeed warns me against it: "Reference to a non-shared member
requires an object reference."

Public Class Nest
Private mstrTitle As String
Private mstrSubNests As SubNest
Public Property Title() As String
Public Property SubNests() As SubNest

Public Class SubNest
Private mstrNestBoolean As Boolean
Public Property NestBoolean() As Boolean
Public Sub Feck()
If NestBoolean = True Then
Title = "Hello"
End If
End Sub
End Class
End Class
--
Cheers, ymt.
Apr 8 '06 #1
1 1792
Yuk Tang <ji********@yah oo.com> wrote in
news:Xn******** *************** ********@130.13 3.1.4:

Leading on from a recent topic, "How does child class access
parent's variables", I would like to ask, what's the most elegant
way of changing a parent/grandparent/great-grandparent's property?

The class Nest has a subclass SubNest. Within SubNest I want to
work with Title. I think if I can pass Title ByRef to the
children and grandchildren, it would work, but VB doesn't do so by
default, and indeed warns me against it: "Reference to a
non-shared member requires an object reference."


I've done a modified version of this, with the parent having a
property that holds the child, and vice versa. So
Parent.Child.Pa rent,etc. I've also included a Title property in the
Parent to let me see what's going on.

Public Class Nest
Private mstrTitle As String
Private mstrSubNests As SubNest
Public Property Title() As String
Public Property SubNests() As SubNest

Public Class SubNest
Private mstrParent As Nest
Public Property Parent() As Nest
End Class

Public Sub New()
Dim sn As New SubNest
SubNests = sn
End Sub
End Class

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim n As New Nest
n.Title = "Hello"
n.SubNests.Pare nt = n
MsgBox("Origina l: " + n.Title)
MsgBox("Nested: " + n.SubNests.Pare nt.Title)
n.SubNests.Pare nt.Title = "There"
MsgBox("Origina l: " + n.Title)
MsgBox("Nested: " + n.SubNests.Pare nt.Title)
n.Title = n.SubNests.Pare nt.Title
MsgBox("Origina l: " + n.Title)
MsgBox("Nested: " + n.SubNests.Pare nt.Title)
End Sub

So this creates a Parent, sets its Title to "Hello", and sets
Child.Parent to Parent. So Parent.Title and Child.Parent.Ti tle
should both be "Hello". This is indeed the case.

Hello, Hello

The next step sets Child.Parent.Ti tle to "There", but leaves
Parent.Title alone. The expected result should therefore be "Hello"
and "There". However, this is what I get.

There, There

The last step should set Parent.Title to "There" as well, but it
seems that's already been done in step 2.

There, There

Doing further experiments, it looks as though setting one
automatically sets the other. Can anyone explain scopes or whatever
it is that's going on?
--
Cheers, ymt.
Apr 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3805
by: pablo | last post by:
Dear NewsGroupers, I am relatively new to OOP and cannet get my head around this problem. I have two classes. Class Child extends Parent. There is no constructor for the Child class. So when I create a child object the constructor for the parent object is called. That works fine. But now I have the problem that I want to add an already existing Parent object to create a new Child object. How can this be done?
24
3500
by: Charles Crume | last post by:
Hello; My "index.htm" page has 3 frames (content, navigation bar, and logo). I set the "SRC" of the "logo" frame to a blank gif image and then want to change it's contents after the other two frames have been loaded by using a javascript statement from the "navigation" frame, as shown below: top.window.ccs_logo.src = 'images/ccs_logo.gif'; alert(top.window.ccs_logo.src);
4
2436
by: TS | last post by:
When i try to access the page class or parent properties inside a server control that is nested in another server control, they are null. I don't even call CreateChildControls for the parent control until its pre-render event, so i know the parent control is on the page. Any ideas? thanks
1
3319
by: V | last post by:
Hello! I made custom control with tables and labels in it. In my page I have several of these controls. Each one should have different color of tables etc. I have different SkinIDs for that. When my Default page loads I'd like to set SkinID for each of these controls.
11
2847
by: manstey | last post by:
Hi, I am having trouble designing my classes. I have two classes. The first one wraps around an old-style class called oref Class CacheClass(object): def __init__(self, obj):
3
7344
by: bulldog8 | last post by:
I am having problems with changing a frames source file for Mozilla (1.5.0.4). The followig code works for IE: <script type="text/javascript"> var imgP = new Image(); function ShowPic(ShowThis, wdth, hght) { imgP.src = "../pics/' + ShowThis + '" xw = 500; yh = 500*(hght/wdth); window.document.getElementById("graphic").innerHTML = '<img src="../
3
18700
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however, working with complex reports is tricky Assumption: Reader of this article have basic knowledge of creating data reports. Creating a Parent-Child Command and create a DataReport Suppose we have a database called company with two tables ...
3
1776
by: Berlin Brown | last post by:
http://www.w3schools.com/htmldom/prop_frame_scrolling.asp I want to be able to get this example working with Internet explorer. it works fine in firefox. Does anyone have an idea how to resolve this bug. 'Basically, I want to be able to change the properties of a frame after the properties have been defined. E.g. turn scrolling from "no" to "yes"
1
1945
by: ranger979 | last post by:
I am using the emptydatatemplate for a gridview control. I have a detailsview control within the emptydatatemplate. In the detailsview I have another templatefield that contains an imagebutton control and a textbox control. <EmptyDataTemplate> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:DetailsView ID="DetailsView1"...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.