Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array of undefined length in new object

Status
Not open for further replies.

wimvanherp

Programmer
Mar 3, 2001
149
BE
I want to make an object with an array of wich the size is not yet defined. It's a bit like
a treeview, if you make a new treeview object you get a property items of wich the size
is not yet defined, because you can always add new items. But how do I define this in
the definition of the class ? I tried with f.i. int ARRAY[] but that does not help.
So a question to Borland insiders : how does Borland define the property items in TTreeview
to be a array of a undefined length ?

regards Wim Vanherp
Wim.Vanherp@myself.com
 
Greetinx!

You cant make undefined length arrays, but you can make an dynamical arrays, like VECTORs! Also, you can write your own type of dynamical arrays. It can consist of three fields:
1. Pointer to array buffer;
2. Current quantity of items in the array;
3. Maximum quantity of items in the array or array buffer size.
If you adds a new item to array, and, at same time, maximum quantity of items is equal to current quantity of items i.e. array is full, you should replace buffer size to new buffer, size of which wiil be more then old buffer size, in example in 2 times. Then you should copy data from old to new buffer and make access to the new buffer.


Happy programming!))
 
you could also use a linked list that you could overload with the [] operator and any other operations.

Matt
 
Thanks for the tips .
Is there a component or a function in Builder to make a linked list ?

Wim Wim Vanherp
Wim.Vanherp@myself.com
 
Greetinx!

What do you mean about 'linked list'? Happy programming!))
 
Builder doesn't have a component but the STL has lists. Look at the list template. BTW, there was an excellent article in C/C++ Users Journal a couple of months ago about the differences between list, vector, and deque and when to use which one. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top