Solved

control array Borland C++ Builder Visual Basic

Posted on 2001-07-30
5
688 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
Comment Utility
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
Comment Utility
I hope, my info helps you. Alex
0
 

Author Comment

by:lirtua
Comment Utility
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
Comment Utility
Oh - forgot to mention this also in source code:

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

Author Comment

by:lirtua
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now