Object Array / collections
-
Im working on a little program that does on command drawing eventually plotting / cutting (Very lucky to have opportunity to experiment on high tech peice of machinary :o) )I had a program thatused a CArray collection but I need to have another two variables in a adition to a point. I tried using a class which had all neccissary variables and then tried to use it in a simar type collection but this didnt work. How should I go about this??? CObArray?? I need to be able to 'add'Items and then read items sequentially. thanks for the time
-
Im working on a little program that does on command drawing eventually plotting / cutting (Very lucky to have opportunity to experiment on high tech peice of machinary :o) )I had a program thatused a CArray collection but I need to have another two variables in a adition to a point. I tried using a class which had all neccissary variables and then tried to use it in a simar type collection but this didnt work. How should I go about this??? CObArray?? I need to be able to 'add'Items and then read items sequentially. thanks for the time
You can create separate instances of the class using new. Then add the pointer to that class data to the CObArray. Just remember to create a function to properly delete items prior to emptying the array, or else you will discover that you have memory leaks. I usually use a for loop to fetch each item's pointer, delete the items via the pointer, then erase all the pointers by calling RemoveAll on the array when I am done with the data.
-
Im working on a little program that does on command drawing eventually plotting / cutting (Very lucky to have opportunity to experiment on high tech peice of machinary :o) )I had a program thatused a CArray collection but I need to have another two variables in a adition to a point. I tried using a class which had all neccissary variables and then tried to use it in a simar type collection but this didnt work. How should I go about this??? CObArray?? I need to be able to 'add'Items and then read items sequentially. thanks for the time
See: http://home.socal.rr.com/samhobbs/VC/Collections.html The CObList sample can probably be used as an exmple of a CObArray also, with the obvious variations. I think, however, that a CArray would be good too and might be easier. If you used it as in: CArray m_FieldsRecords; then it would store and retrieve your class items and you could delete everything with a simple: m_FieldsRecords.RemoveAll(); when you are through. So what was the problem with CArray? I have used them and they work well and are easy to use. I think it would be worthwhile to determine what the problem is and solve it.
-
See: http://home.socal.rr.com/samhobbs/VC/Collections.html The CObList sample can probably be used as an exmple of a CObArray also, with the obvious variations. I think, however, that a CArray would be good too and might be easier. If you used it as in: CArray m_FieldsRecords; then it would store and retrieve your class items and you could delete everything with a simple: m_FieldsRecords.RemoveAll(); when you are through. So what was the problem with CArray? I have used them and they work well and are easy to use. I think it would be worthwhile to determine what the problem is and solve it.
Well In fact I did solve the problem with the CArray and again Im sorry for the poorly written post I was a little mindboggled last night!!! I have a class whose constructor is as follows JPoint(CPoint CP, int state, int Ptool); This is the object I needed an array of.. In a SetCoordinates function I had code similar to this: FixedMap.Add(JPoint((100,100),0,1)); Still a newbee I assumed that (100,100) would be assumed to be the CPoint required by the JPoint constructor; And the fact I recieved no compiler errors lead me to beleive it should work. But when it came draw the points in another function nothing was displayed... The problem was not prefixing (100,100) with CPoint as follows FixedMap.Add(JPoint(CPoint(100,100),0,1)); Shouldve known better right???