Sign in to follow this  

Giving objects in arrays properties

This topic is 3485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a menu that has an array of Menu Items. I'm wondering how I can change the properties of the objects in the array, each object has 3 things to change if it make a difference

Share this post


Link to post
Share on other sites
What programming language? "Property" sounds like you're referring to C# or Obj-c, or do you mean "property" in the generic sense?

Share this post


Link to post
Share on other sites
A Win32 menu or what? I have never dealt with any time of menu, so I'm probabaly clueless. If it's a custom menu you wrote, I guess make a class called MenuItem and in it, have the public variables things like int width; int height; string text, and other properties you want. Then make an array of MenuItem so when you add something to that array, also set the properties of it you want. I could be completely off and not help at all, but w/e lol.

Share this post


Link to post
Share on other sites
What you said is exactly what I'm trying to do, but I don't know how to give the objects the values

Share this post


Link to post
Share on other sites
I'm used to C++, but does C# have #include <vector>? if so, just to vector<MenuItem*> menuItems; to make an array of menuitem pointers. Then to add to it, just do MenuItem* newItem; newItem->property = "whatever"; menuItems.push_back(newItem);

[Edited by - Tenac on July 2, 2008 4:32:25 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by I Am Legend
What you said is exactly what I'm trying to do, but I don't know how to give the objects the values


You specify the object whose value you want to set, in the normal way that you specify an element of an array, and then set its property in the normal way.


myArray[0].foo = 42
^ ^^^^^^^ ^ ^^
| ||||||| + ++---------------------------------------+
| ||||+++-+-------------------------------------+ |
| |||+----+---------------------------------+ | |
| ||| +---------------------------+ | | |
| look at the 0th element | | | |
+------------------------- of myArray, and set its foo to 42.

Share this post


Link to post
Share on other sites
Zahlman, did you just type out that diagram? It's really cool lol.

Share this post


Link to post
Share on other sites
Do you simply mean something like this?


foreach (MenuItem menuItem in menuItemArray)
{
menuItem.Property1 = something;
menuItem.Property2 = somethingElse;
menuItem.Property3 = somethingElse;
}


Share this post


Link to post
Share on other sites
Thank you so much, that got it working.Yayers:)

<Edit> Zahlman I mean, I didn't refresh that page for a while so I didn't see your reply smitty. Thanks anyway</edit>

Share this post


Link to post
Share on other sites

This topic is 3485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this