If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Borland C++ Builder

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-04, 10:39
fastor fastor is offline
Registered User
 
Join Date: Nov 2004
Posts: 1
Borland C++ Builder

Hallo to everybody! I'm new here. Very nice Forum!
I hope that somenone could help me!

I would like to know why it is not possible to declare a dinamic array of VCL objects.

e.g.:

TButton *DinamVett=new TButton[Max_Dim];

I would like that Max_Dim is a variable and not a constant. How can I obtain this? Is there another way to do it?


Thank you!
Reply With Quote
  #2 (permalink)  
Old 11-06-04, 10:40
sundialsvcs sundialsvcs is offline
Registered User
 
Join Date: Oct 2003
Posts: 706
In the Delphi and C++Builder environments, an "object" is a "pointer." When you execute the constructor, by means of New, three things happen:
  • A block of memory is allocated and set entirely to zero. This will include space for the object description record (positioned at a negative offset from the returned pointer), the object's private and public variables, and the method-table pointers.
  • The object's constructor(s) are called to initialize the new object.
  • A pointer to the memory-block is returned as the return-value of New.
You can use this return-value in a number of ways. One very convenient way to store it is to put it in a TList, which you'll see that the VCL itself does in many places. (For example, a TForm contains a list of all the controls that exist on it.) You can assign it to a local variable. By any of these means you can then invoke the object's properties and methods.

I think you'll accomplish what you want by using a TList.

Bear in mind: There is no "reference counting" for objects and no automatic cleanup: what you New, you must also eventually Free. Before you delete the TList you'll probably need to iterate through it and Free everything that it points to.
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On