Solved

control array Borland C++ Builder Visual Basic

Posted on 2001-07-30
5
701 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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…

737 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