Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004

    Unanswered: 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.


    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!

  2. #2
    Join Date
    Oct 2003
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts