ICloneable - Please help.....please.... 
Author Message
 ICloneable - Please help.....please....

Good afternoon all,

I am aware of all of the examples previously posted in the user groups
BUT I feel my question is warranted due to its unusual nature and
maybe it will help other new users.

Q1. I am trying to use ICloneable to make a copy of a member of my
class.

The issue herein lies that I have got 2 levels of inheritance.

Does this matter ?

Or is it my routine for cloning which is the issue?

The error is as follows:
Error: "Child is not a child control of this parent"

Can someone please have a look at the following simple routine. The
error occurs at the bottom of the form load event.

My thoughts are:

 - the cloning routine in the ""MySuperControl" is only performing a
copy by reference of my Obj1 control and thus when I change my 2nd
object's name to "Lillee" this also changes "Object1's" name to
"Lillee" BUT it should remain as "Dennis", also I can NOT add the
control to the form panel.

Class MySuperControl : Implements ICloneable
 Inherits Label

 public overrideable function Clone() as object
  return MyClass.Memberwiseclone
 end function
End class

Class MyControl
 Inherits MySuperControl
 Implements ICloneable

 public overides function Clone() as object implements
System.ICloneable.Clone
  Return MyClass.Memberwiseclone
 end function

End Class

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        Dim obj1 As New MyControl()

        ' now draw the controls onto the form
        obj1.Location = New System.Drawing.Point(Me.Width \ 2, 20)
        obj1.TabIndex = Me.Panel1.Controls.Count + 1
        obj1.Visible = True
        obj1.BorderStyle = BorderStyle.FixedSingle
        obj1.Text = "Dennis"

        'ADD TO THE PANEL
        Me.Panel1.Controls.Add(obj1)

        'CLONE HERE
        Dim obj2 As ScreenObject= obj1.Clone

        obj2.Location = New System.Drawing.Point(Me.Width \ 2, 40)
        obj2.TabIndex = Me.Panel1.Controls.Count + 1
        obj2.BorderStyle = BorderStyle.FixedSingle
        obj2.Text = "Lillee"
        obj2.Visible = True

        'HERE IS WHERE THE CODE ERRORS OUT
        'Error: "Child is not a child control of this parent"
        Me.Panel1.Controls.Add(obj2)
End Sub



Fri, 22 Apr 2005 11:56:39 GMT  
 ICloneable - Please help.....please....
LARB,

    I assume that part of it has to do with the fact that you are not
cloning the handle to the control (which you really can not).  Can you post
the code for your Clone method?  This is what would be most helpful.

--
          - Nicholas Paldino [.NET/C# MVP]


Quote:
> Good afternoon all,

> I am aware of all of the examples previously posted in the user groups
> BUT I feel my question is warranted due to its unusual nature and
> maybe it will help other new users.

> Q1. I am trying to use ICloneable to make a copy of a member of my
> class.

> The issue herein lies that I have got 2 levels of inheritance.

> Does this matter ?

> Or is it my routine for cloning which is the issue?

> The error is as follows:
> Error: "Child is not a child control of this parent"

> Can someone please have a look at the following simple routine. The
> error occurs at the bottom of the form load event.

> My thoughts are:

>  - the cloning routine in the ""MySuperControl" is only performing a
> copy by reference of my Obj1 control and thus when I change my 2nd
> object's name to "Lillee" this also changes "Object1's" name to
> "Lillee" BUT it should remain as "Dennis", also I can NOT add the
> control to the form panel.

> Class MySuperControl : Implements ICloneable
>  Inherits Label

>  public overrideable function Clone() as object
>   return MyClass.Memberwiseclone
>  end function
> End class

> Class MyControl
>  Inherits MySuperControl
>  Implements ICloneable

>  public overides function Clone() as object implements
> System.ICloneable.Clone
>   Return MyClass.Memberwiseclone
>  end function

> End Class

>  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>         Dim obj1 As New MyControl()

>         ' now draw the controls onto the form
>         obj1.Location = New System.Drawing.Point(Me.Width \ 2, 20)
>         obj1.TabIndex = Me.Panel1.Controls.Count + 1
>         obj1.Visible = True
>         obj1.BorderStyle = BorderStyle.FixedSingle
>         obj1.Text = "Dennis"

> 'ADD TO THE PANEL
>         Me.Panel1.Controls.Add(obj1)

> 'CLONE HERE
>         Dim obj2 As ScreenObject= obj1.Clone

>         obj2.Location = New System.Drawing.Point(Me.Width \ 2, 40)
>         obj2.TabIndex = Me.Panel1.Controls.Count + 1
>         obj2.BorderStyle = BorderStyle.FixedSingle
>         obj2.Text = "Lillee"
>         obj2.Visible = True

> 'HERE IS WHERE THE CODE ERRORS OUT
> 'Error: "Child is not a child control of this parent"
>         Me.Panel1.Controls.Add(obj2)
> End Sub



Fri, 22 Apr 2005 22:50:32 GMT  
 ICloneable - Please help.....please....
Nicholas,

thankyou for your reply.

The code "is as is" as they say. You have all my code.

I think you right though. I mean that I can not get the label" control
window handle.

Anymore thoughts?

Regards

Peter


Quote:
> LARB,

>     I assume that part of it has to do with the fact that you are not
> cloning the handle to the control (which you really can not).  Can you post
> the code for your Clone method?  This is what would be most helpful.

> --
>           - Nicholas Paldino [.NET/C# MVP]



> > Good afternoon all,

> > I am aware of all of the examples previously posted in the user groups
> > BUT I feel my question is warranted due to its unusual nature and
> > maybe it will help other new users.

> > Q1. I am trying to use ICloneable to make a copy of a member of my
> > class.

> > The issue herein lies that I have got 2 levels of inheritance.

> > Does this matter ?

> > Or is it my routine for cloning which is the issue?

> > The error is as follows:
> > Error: "Child is not a child control of this parent"

> > Can someone please have a look at the following simple routine. The
> > error occurs at the bottom of the form load event.

> > My thoughts are:

> >  - the cloning routine in the ""MySuperControl" is only performing a
> > copy by reference of my Obj1 control and thus when I change my 2nd
> > object's name to "Lillee" this also changes "Object1's" name to
> > "Lillee" BUT it should remain as "Dennis", also I can NOT add the
> > control to the form panel.

> > Class MySuperControl : Implements ICloneable
> >  Inherits Label

> >  public overrideable function Clone() as object
> >   return MyClass.Memberwiseclone
> >  end function
> > End class

> > Class MyControl
> >  Inherits MySuperControl
> >  Implements ICloneable

> >  public overides function Clone() as object implements
> > System.ICloneable.Clone
> >   Return MyClass.Memberwiseclone
> >  end function

> > End Class

> >  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> >         Dim obj1 As New MyControl()

> >         ' now draw the controls onto the form
> >         obj1.Location = New System.Drawing.Point(Me.Width \ 2, 20)
> >         obj1.TabIndex = Me.Panel1.Controls.Count + 1
> >         obj1.Visible = True
> >         obj1.BorderStyle = BorderStyle.FixedSingle
> >         obj1.Text = "Dennis"

> > 'ADD TO THE PANEL
> >         Me.Panel1.Controls.Add(obj1)

> > 'CLONE HERE
> >         Dim obj2 As ScreenObject= obj1.Clone

> >         obj2.Location = New System.Drawing.Point(Me.Width \ 2, 40)
> >         obj2.TabIndex = Me.Panel1.Controls.Count + 1
> >         obj2.BorderStyle = BorderStyle.FixedSingle
> >         obj2.Text = "Lillee"
> >         obj2.Visible = True

> > 'HERE IS WHERE THE CODE ERRORS OUT
> > 'Error: "Child is not a child control of this parent"
> >         Me.Panel1.Controls.Add(obj2)
> > End Sub



Sat, 23 Apr 2005 04:51:11 GMT  
 ICloneable - Please help.....please....
Peter,

    Sorry, I didn't see that.

    The handle can not be cloned.  You can't just do a memberwise clone of a
control since it holds internally a handle to an unmanged resource, which is
not cloned.  If you want to clone it, you have to clone almost all of the
managed properties, but not the handle, and then let the clone create the
new handle.

--
          - Nicholas Paldino [.NET/C# MVP]


Quote:
> Nicholas,

> thankyou for your reply.

> The code "is as is" as they say. You have all my code.

> I think you right though. I mean that I can not get the label" control
> window handle.

> Anymore thoughts?

> Regards

> Peter




- Show quoted text -

Quote:
> > LARB,

> >     I assume that part of it has to do with the fact that you are not
> > cloning the handle to the control (which you really can not).  Can you
post
> > the code for your Clone method?  This is what would be most helpful.

> > --
> >           - Nicholas Paldino [.NET/C# MVP]



> > > Good afternoon all,

> > > I am aware of all of the examples previously posted in the user groups
> > > BUT I feel my question is warranted due to its unusual nature and
> > > maybe it will help other new users.

> > > Q1. I am trying to use ICloneable to make a copy of a member of my
> > > class.

> > > The issue herein lies that I have got 2 levels of inheritance.

> > > Does this matter ?

> > > Or is it my routine for cloning which is the issue?

> > > The error is as follows:
> > > Error: "Child is not a child control of this parent"

> > > Can someone please have a look at the following simple routine. The
> > > error occurs at the bottom of the form load event.

> > > My thoughts are:

> > >  - the cloning routine in the ""MySuperControl" is only performing a
> > > copy by reference of my Obj1 control and thus when I change my 2nd
> > > object's name to "Lillee" this also changes "Object1's" name to
> > > "Lillee" BUT it should remain as "Dennis", also I can NOT add the
> > > control to the form panel.

> > > Class MySuperControl : Implements ICloneable
> > >  Inherits Label

> > >  public overrideable function Clone() as object
> > >   return MyClass.Memberwiseclone
> > >  end function
> > > End class

> > > Class MyControl
> > >  Inherits MySuperControl
> > >  Implements ICloneable

> > >  public overides function Clone() as object implements
> > > System.ICloneable.Clone
> > >   Return MyClass.Memberwiseclone
> > >  end function

> > > End Class

> > >  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles MyBase.Load
> > >         Dim obj1 As New MyControl()

> > >         ' now draw the controls onto the form
> > >         obj1.Location = New System.Drawing.Point(Me.Width \ 2, 20)
> > >         obj1.TabIndex = Me.Panel1.Controls.Count + 1
> > >         obj1.Visible = True
> > >         obj1.BorderStyle = BorderStyle.FixedSingle
> > >         obj1.Text = "Dennis"

> > > 'ADD TO THE PANEL
> > >         Me.Panel1.Controls.Add(obj1)

> > > 'CLONE HERE
> > >         Dim obj2 As ScreenObject= obj1.Clone

> > >         obj2.Location = New System.Drawing.Point(Me.Width \ 2, 40)
> > >         obj2.TabIndex = Me.Panel1.Controls.Count + 1
> > >         obj2.BorderStyle = BorderStyle.FixedSingle
> > >         obj2.Text = "Lillee"
> > >         obj2.Visible = True

> > > 'HERE IS WHERE THE CODE ERRORS OUT
> > > 'Error: "Child is not a child control of this parent"
> > >         Me.Panel1.Controls.Add(obj2)
> > > End Sub



Sat, 23 Apr 2005 06:06:08 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

2. Please help!!!!Please help!!!!Please help!!!!

3. help: Guru needed please please please

4. HELP please on QUEUES!! please, please, please, please,please...

5. PLEASE PLEASE PLEASE PLEASE

6. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

7. PLEASE PLEASE HELP HELP...question on interleaving C functions

8. Please Please Help!!!!!!

9. simulate dragDrop of ListView Item -- Please Please Help!!!!

10. Very Urgent !!! please please help

11. please help with algorythm, PLEASE

12. Please Please Help!!!!!!

 

 
Powered by phpBB® Forum Software