473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

array of TCheckBox - is it possiible?

Hello there,
i need to create some(possible 2) checkboxes:

TCheckBox *aCb = new TCheckBox(this);
aCb->Parent = this;
aCb->Left = 20;
aCb->Top = 120;

TCheckBox *aCb1 = new TCheckBox(this);
aCb1->Parent = this;
aCb1->Left = 40;
aCb1->Top = 120;

But the problem is i don't know,how much checkboxes will be created,
possible X.
I do not shure, is it possible to create dynamic array of CheckBoxes?
The following code isn't correct:

int X=16;
TCheckBox[X] *aCb = new[X] TCheckBox(this);
for(int i=0;i<X;i++)
aCb[i] = new TCheckBox(this);

So, is it possible to create array of TCheckBox?
Thank you.

Jul 23 '05 #1
6 1846
Encapsulin wrote:
So, is it possible to create array of TCheckBox?


Yes, as you can have arrays of any kind... What you do with your array
and what it may mean, it's up to you.
Jul 23 '05 #2
Encapsulin wrote:
I do not shure, is it possible to create dynamic array of CheckBoxes?


Use std::vector. See http://www.sgi.com/tech/stl/Vector.html

-Alan
Jul 23 '05 #3


Alan Johnson wrote:
Encapsulin wrote:
I do not shure, is it possible to create dynamic array of CheckBoxes?


Use std::vector. See http://www.sgi.com/tech/stl/Vector.html

-Alan


If this TCheckBox you mention is a VCL (Borland) control, you may not
use std::vector<TCheckBox>. One option (I use it) is
std::vector<std::auto_ptr<TCheckBox> >, which makes all cleaning up easy

Jul 23 '05 #4
Zara wrote:

Alan Johnson wrote:
Encapsulin wrote:
I do not shure, is it possible to create dynamic array of CheckBoxes?


Use std::vector. See http://www.sgi.com/tech/stl/Vector.html

-Alan

If this TCheckBox you mention is a VCL (Borland) control, you may not
use std::vector<TCheckBox>. One option (I use it) is
std::vector<std::auto_ptr<TCheckBox> >, which makes all cleaning up easy


auto_ptr is not suitable for storage in standard containers.
Specifically, it doesn't meet the CopyConstructible or Assignable
concept requirements. It may _seem_ to work with some STL
implementations, but it is not a safe thing to do. Something like
boost::shared_ptr is more appropriate for storage in containers.

As for TCheckBox, I don't know anything about it, so I can't say whether
it meets the requirements for storage in standard containers.

-Alan
Jul 23 '05 #5
Zara wrote:
Alan Johnson wrote:
Encapsulin wrote:
I do not shure, is it possible to create dynamic array of CheckBoxes?


Use std::vector. See http://www.sgi.com/tech/stl/Vector.html

-Alan


If this TCheckBox you mention is a VCL (Borland) control, you may
not use std::vector<TCheckBox>. One option (I use it) is
std::vector< std::auto_ptr<TCheckBox> >


Using auto_ptr in a vector is treading on very thin ice. Read
the section titled "Things Not To Do, and Why Not To Do Them" at
http://www.gotw.ca/publications/usin...ffectively.htm

It would be safe to have std::vector< boost::shared_ptr<TCheckBox> >
but boost and Borland don't mix too well.

My preferred option would be to have std::vector<TCheckBox *>
as a member of an object, and delete the pointers in the
object's destructor.

Note (Borland-specific): In this case, the best solution is
to set the checkbox's Owner property to 'this' . Then
the parent object will automatically delete the pointer
when the parent object is deleted.

Jul 23 '05 #6


Old Wolf wrote:
(...)
Using auto_ptr in a vector is treading on very thin ice. Read
the section titled "Things Not To Do, and Why Not To Do Them" at
http://www.gotw.ca/publications/usin...ffectively.htm
Thank's for the link. As always, one is never the first to do
something. I created a "const_auto_ptr" class myself, thinking I was
cute. Ha! And I seee Borland doesn´t warn of this misuse.
It would be safe to have std::vector< boost::shared_ptr<TCheckBox> >
but boost and Borland don't mix too well.
Really! Boralnd CBuilderX Personal comes with a copy of Boost library
and no way to make it work with the compiler.
My preferred option would be to have std::vector<TCheckBox *>
as a member of an object, and delete the pointers in the
object's destructor.
Generically:

template <typename T>
class VCLArray
{
/*...*/
private:
typedef T* elementType;
typedef std::vector<elementType> arrayType;
arrayType data;
/*...*/
public:
/*...*/
~VCLArray()
{
for (typename arrayType::iterator
i=data.begin();i!=data.end();++i)
delete *i;
}
/*...*/
};

Note (Borland-specific): In this case, the best solution is
to set the checkbox's Owner property to 'this' . Then
the parent object will automatically delete the pointer
when the parent object is deleted.


Only if this derives from TComponent

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Reed Law | last post by:
I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' => '/youth/pics/Member pics/', 'text' => 'Member pics', ),...
2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
0
by: sjaak538 | last post by:
Hello I've a question about printing complex array's with print_r $xmlC->obj_data I get this example bellow But can anybody give me one example on how to echo $xmlC->obj_data; I try'd with...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: devilcore | last post by:
Hello, In C++ Builder, is there any way that I can set the a TCheckBox caption as multiline text? I'm trying to include a long set of text in the checkbox caption. Hope I can get some answers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.