473,387 Members | 1,779 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.

help me figure this out - control collection

I wrote a ton of code in the older VC 6.0 and admit to being behind
the times.

I struggled through and prototyped an application in 2005.net VB that
I am now converting to VC++ in 2005.net, not sharp. To begin with,
the following code clears all the checkbox controls in a groupbox of
60 checks. It works but I think it could be simplified.

For instance, I don't get the "^" character but it has something to do
with high level or system level classes???

But in the code below, if I don't define "h" with CheckBox^ then I
can't get this assignment to work "h = (CheckBox^)this->GroupBox4-
>Controls[x];" no matter how many times I tried to typedef the right
hand side. So, by using the "^" I can't get the comparison "if (this-
>GroupBox4->Controls[x]->GetType() ==b.GetType() )" to work by subbing
in "==h->GetType()". So I used a dummy CheckBox variable, "b" and the
comparison goes true when the control indexed by "x" in Groupbox4 is a
CheckBox.

tThe bottom line is that I shouldn't need to use "b" and should be
able to extract the type from "h" or some other system type for a
checkbox.

This is a long way to say I would like to eliminate 'b' in the
following routine. If you can shed some light on "^" in the process,
I would appreciate it.
thanks,

Jerry

{
CheckBox^ h;
CheckBox b;
int x;
for(x=1; x < this->GroupBox4->Controls->Count; x++)
{
if(this->GroupBox4->Controls[x]->GetType() ==b.GetType() ) // why b?
{
h = (CheckBox^)this->GroupBox4->Controls[x]; // why ^?
h->Checked=false;
}
}

}

Jul 27 '07 #1
3 1289
jerry wrote:
I wrote a ton of code in the older VC 6.0 and admit to being behind
the times.

I struggled through and prototyped an application in 2005.net VB that
I am now converting to VC++ in 2005.net, not sharp. To begin with,
the following code clears all the checkbox controls in a groupbox of
60 checks. It works but I think it could be simplified.

For instance, I don't get the "^" character but it has something to do
with high level or system level classes???

But in the code below, if I don't define "h" with CheckBox^ then I
can't get this assignment to work "h = (CheckBox^)this->GroupBox4-
>Controls[x];" no matter how many times I tried to typedef the right
hand side. So, by using the "^" I can't get the comparison "if (this-
>GroupBox4->Controls[x]->GetType() ==b.GetType() )" to work by subbing
in "==h->GetType()". So I used a dummy CheckBox variable, "b" and the
comparison goes true when the control indexed by "x" in Groupbox4 is a
CheckBox.

tThe bottom line is that I shouldn't need to use "b" and should be
able to extract the type from "h" or some other system type for a
checkbox.

This is a long way to say I would like to eliminate 'b' in the
following routine. If you can shed some light on "^" in the process,
I would appreciate it.
thanks,

Jerry

{
CheckBox^ h;
CheckBox b;
int x;
for(x=1; x < this->GroupBox4->Controls->Count; x++)
{
if(this->GroupBox4->Controls[x]->GetType() ==b.GetType() ) // why b?
{
h = (CheckBox^)this->GroupBox4->Controls[x]; // why ^?
h->Checked=false;
}
}

}
jerry:

The version of C++ that supports the .NET framework is called C++/CLI.
The ^ denotes a "tracking handle", which is analogous to a pointer in
ordinary C++.

I would suggest that you get a book on C++/CLI. It is not possible to
use a language unless you know the syntax.

I am not into .NET programming (yet?), but I would say your main problem
is the following. When you write

CheckBox^ h;

the h does not refer to anything, so you cannot call GetType(), or any
other method, on it. On the other hand, when you write

CheckBox b;

you are actually creating a CheckBox object, using "stack symantics".
Unlike ordinary C++, the object is in fact created on the heap, but
gives the illusion of being on the stack. Anyway, because you have a
real object, you can call GetType() on it.

I'm sure someone else can tell you a cleaner way of writing your program.

--
David Wilkinson
Visual C++ MVP
Jul 27 '07 #2
tThe bottom line is that I shouldn't need to use "b" and should be
able to extract the type from "h" or some other system type for a
checkbox.
Maybe you are wanting "CheckBox::typeid"?
Aug 20 '07 #3

"jerry" <je******@pacbell.netwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
>I wrote a ton of code in the older VC 6.0 and admit to being behind
the times.

I struggled through and prototyped an application in 2005.net VB that
I am now converting to VC++ in 2005.net, not sharp. To begin with,
the following code clears all the checkbox controls in a groupbox of
60 checks. It works but I think it could be simplified.

For instance, I don't get the "^" character but it has something to do
with high level or system level classes???
That's a pointer into garbage collected memory. It's different from
pointers in two important ways:

The garbage collector keeps objects alive only if there is a ^ tracking
handle.
The garbage collector updates ^ tracking handles as it compacts memory.
>
But in the code below, if I don't define "h" with CheckBox^ then I
can't get this assignment to work "h = (CheckBox^)this->GroupBox4-
>>Controls[x];" no matter how many times I tried to typedef the right
hand side. So, by using the "^" I can't get the comparison "if (this-
>>GroupBox4->Controls[x]->GetType() ==b.GetType() )" to work by subbing
in "==h->GetType()". So I used a dummy CheckBox variable, "b" and the
comparison goes true when the control indexed by "x" in Groupbox4 is a
CheckBox.

tThe bottom line is that I shouldn't need to use "b" and should be
able to extract the type from "h" or some other system type for a
checkbox.

This is a long way to say I would like to eliminate 'b' in the
following routine. If you can shed some light on "^" in the process,
I would appreciate it.
thanks,

Jerry

{
CheckBox^ h;
CheckBox b;
int x;
for(x=1; x < this->GroupBox4->Controls->Count; x++)
{
if(this->GroupBox4->Controls[x]->GetType() ==b.GetType() ) // why b?
{
h = (CheckBox^)this->GroupBox4->Controls[x]; // why ^?
h->Checked=false;
}
}

}

Aug 20 '07 #4

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

Similar topics

12
by: Jozef | last post by:
Hello, Does anyone here know for sure, when you do a For Each loop on a forms controls collection, does Access cycle through them in Alphabetical order or control ID or ???. Any ideas? ...
2
by: Cider123 | last post by:
Trying to figure out how to replicate the same interface as what a ListView control has. I have everything working for the most part, with exception of 1 minor setback. I can't seem to pass...
3
by: Robert Johnson | last post by:
I need to figure out how to go through all of the WebControls on a form, find all the ones that are named with a "txt" prefix (ie txtFirstName), and then retrieve the WebControl ID, Text (value),...
5
by: Arnold | last post by:
Hi, Im building a WebCustomControl. In my principal class (Inherits from WebControl), have a property of type MyCollection (Inherits from CollectionBase), which is a MyItem collection. To mantain...
0
by: Tom | last post by:
I am having a really annoying issue with serialization and a .NET User Control I am writing. For example, let's say I have a couple of classes in my control - first class is like: Public Class...
2
by: DJG | last post by:
I need some help with a TreeView control in VB.Net I've got a datatable with about 8000 rows. 500 are 'folders', and the other 7500 rows are 'jobs'. It's a logical representation of some data,...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.