?
Solved

control array Borland C++ Builder Visual Basic

Posted on 2001-07-30
5
Medium Priority
?
713 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 180 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

770 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