"not accessible in this context because it is protected"

  • Thread starter Thread starter eBob.com
  • Start date Start date
E

eBob.com

I'm getting this error on this statement ...

Dim TA_rect As Rectangle = CType(Me.ClientRectangle.memberwiseclone(),
Rectangle)

"Me" inherits from UserControl.

I'm not an OOD guru but maybe I sort of understand the problem. If so, this
is not my fault, right? Since I can access ClientRectangle I don't see why
I can't clone it. Is there anything easier/better than typing out all of
the code to make a field by field copy?

Thanks, Bob
 
I'm getting this error on this statement ...

Dim TA_rect As Rectangle = CType(Me.ClientRectangle.memberwiseclone(),
Rectangle)

"Me" inherits from UserControl.

I'm not an OOD guru but maybe I sort of understand the problem. If so, this
is not my fault, right? Since I can access ClientRectangle I don't see why
I can't clone it. Is there anything easier/better than typing out all of
the code to make a field by field copy?

Thanks, Bob

Dim TA_rect As Rectangle = Me.ClientRectangle

You get an error because Rectangle hides the MemberwiseClone method,
probably because it is unnecessary since Rectangle is a Value type.

Because Rectangle is a Value type the above statement will make a copy
since Value types are copied on assignment.
 
Jack Jackson said:
Dim TA_rect As Rectangle = Me.ClientRectangle

You get an error because Rectangle hides the MemberwiseClone method,
probably because it is unnecessary since Rectangle is a Value type.

Because Rectangle is a Value type the above statement will make a copy
since Value types are copied on assignment.

Thank you VERY much Jack. I went back to take another look at the Rectangle
doc and it certainly makes no secret of the fact that Rectangle is a
Structure and not a Class. I don't know if I didn't see that or if the
implication just didn't register.

BUT ... this problem caused me to do some research and thinking and I'd
appreciate your comments, or anyone elses, on what I think I have learned.
In general, in OOP, as the coder of an app, as opposed to the coder of a
class, this area of creating a copy of an object is, I think the technical
term is, mess! In general the case X=Y where Y is a Structure looks
straightforward, but if elements of Y are references then you don't really
end up with a complete copy. Right? The elements within Y better be value
types or other Structures consisting only of value types, etc.. So you
really have to know what your are working with when you need to make a copy
of it. (Of course it's always been the case in programming that you really
have to know what you are doing, but that is easier in some cases than in
others.)

Thanks, Bob
 
Thank you VERY much Jack. I went back to take another look at the Rectangle
doc and it certainly makes no secret of the fact that Rectangle is a
Structure and not a Class. I don't know if I didn't see that or if the
implication just didn't register.

BUT ... this problem caused me to do some research and thinking and I'd
appreciate your comments, or anyone elses, on what I think I have learned.
In general, in OOP, as the coder of an app, as opposed to the coder of a
class, this area of creating a copy of an object is, I think the technical
term is, mess! In general the case X=Y where Y is a Structure looks
straightforward, but if elements of Y are references then you don't really
end up with a complete copy. Right? The elements within Y better be value
types or other Structures consisting only of value types, etc.. So you
really have to know what your are working with when you need to make a copy
of it. (Of course it's always been the case in programming that you really
have to know what you are doing, but that is easier in some cases than in
others.)

Thanks, Bob

Copy is difficult. If members of the thing being copied are
references, then you must determine what behavior you want on copy -
copy the references or generate new instances.
 
Back
Top