Solved

control array Borland C++ Builder Visual Basic

Posted on 2001-07-30
5
698 Views
Last Modified: 2013-11-25
Using Borland C++ Builder, how does one create a control array?

In Visual Basic it is very simple, just highlight the control in design view and paste it, VB asks if you want to create a control array.  In Builder however, the subject of control arrays is not even mentioned in the help files.  It's amazing in such a faithful reproduction of each others products, that this very helpful and simple interface was skipped over.

I would like to create 256 Panels on a Form during run time, and treat them as an array for iteration purposes.

Example source code is desirable.

Thanks in Advance:)
0
Comment
Question by:lirtua
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 60 total points
ID: 6336675
You must to make simething as (example for TButton):
TButton * buttons[200];
for (int i = 0; i < sizeof(buttons) / sizeof(*buttons); ++i)
{
buttons[i] = new TButton(whatever);
}
After that you must add events (example for OnClick:)
void __fastcall TMyForm::MyClick(TObject* Sender)
{
}

for (int i = 0; i < sizeof(buttons) / sizeof(*buttons); ++i)
{
buttons[i]->OnClick = MyClick;
}

See full discussion in
http://www.mers.com/MERLIST/BORLAND/PUBLIC/CPPBUILDER/LANGUAGE/37757.HTML
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6375437
I hope, my info helps you. Alex
0
 

Author Comment

by:lirtua
ID: 6520561
Sorry, the controls are not showing up on my form.  Here is my source code:

   for(int i = 0; i < NUM_IMG; ++i)
   {
      image[i] = new TImage(ScrollBox1);
      image[i]->Picture = Image1->Picture;
      image[i]->Top = i * 10;
      image[i]->Left = 10;
      image[i]->AutoSize = true;
      image[i]->Visible = true;
      image[i]->Invalidate();
   }

On the form is a scrollbox containing an image that has a bitmap loaded at design time.  The control array should be located in the scrollbox and have the same pictures as the design time image.
0
 

Author Comment

by:lirtua
ID: 6520611
Oh - forgot to mention this also in source code:

#define NUM_IMG 10
TImage * image[NUM_IMG];
0
 

Author Comment

by:lirtua
ID: 6520673
Your code is very close.  There is one thing missing though.  For some reason the constructor does not set the Parent property.  So we have to do this explicitly as follows:

      image[i] = new TImage(sbPictureScrollBox);
      image[i]->Parent = sbPictureScrollBox;

With this addition, the code above works.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question