help me figure this out - control collection

  • Thread starter Thread starter jerry
  • Start date Start date
J

jerry

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 said:
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.
 
jerry said:
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;
}
}



}
 
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"?
 
Back
Top