|
-
Mar 28th, 2020, 12:52 PM
#1
Thread Starter
Lively Member
[RESOLVED] Is it possible to nest properties ?
In this case I have a point (HexLocation) which I want to get/set as property for my class.
VB.NET Code:
Private HexLocation As Point
Public Property Location As Point
Get
Return HexLocation
End Get
Set(HexLocation As Point)
End Set
End Property
Then this works just fine afterwards:
VB.NET Code:
Hexagon1.Location = New Point(0, 0)
The problem comes when trying to modify only one of those two values, for example:
"This expression is a value and cannot be the target of an assignation."
So I then tried nesting properties but created a demon:

This didn't work either:

I can't simply have it as a public variable because I need to execute code when it is modified but not enough for it to require a method, I think, so I'm lost.
-
Mar 28th, 2020, 01:20 PM
#2
Re: Is it possible to nest properties ?
The Point data type is a Structure, and therefore cannot be edited. Instead you need to replace it with a whole new value, eg:
Code:
Public Property X As Integer
...
Set(NewX As Integer)
HexLocation = New Point(NewX, HexLocation.Y)
End Set
-
Mar 28th, 2020, 01:49 PM
#3
Thread Starter
Lively Member
Re: Is it possible to nest properties ?
Thanks for the tip, that would work great except it would be acessible this way:
VB.NET Code:
Hexagon1.Location = New Point(0, 0) Hexagon1.X = 33
But I would want X to be a member of Location as such:
VB.NET Code:
Hexagon1.Location = New Point(0, 0) Hexagon1.Location.X = 33
-
Mar 28th, 2020, 02:06 PM
#4
Re: Is it possible to nest properties ?
In that case either create a new Class with similar properties to Point (and use that instead of Point), or possibly call the new property LocationX (and live without the dot).
-
Mar 28th, 2020, 02:13 PM
#5
Thread Starter
Lively Member
Re: Is it possible to nest properties ?
Thanks I created a structure for it similar to point but with the property blocks I needed.
Also the last reply got sent twice mb.
-
Mar 28th, 2020, 10:56 PM
#6
Re: Is it possible to nest properties ?
 Originally Posted by KBConsole
Thanks I created a structure for it similar to point but with the property blocks I needed.
Can you show us your code because I don't see how that could work either.
Tags for this Thread
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
|