Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / August 2007

Tip: Looking for answers? Try searching our database.

help me figure this out - control collection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jerry - 27 Jul 2007 21:12 GMT
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;
        }
    }

}
David Wilkinson - 27 Jul 2007 21:59 GMT
> I wrote a ton of code in the older VC 6.0 and admit to being behind
> the times.
[quoted text clipped - 43 lines]
>
>  }

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.

Signature

David Wilkinson
Visual C++ MVP

Ben Voigt [C++ MVP] - 20 Aug 2007 18:41 GMT
>I wrote a ton of code in the older VC 6.0 and admit to being behind
> the times.
[quoted text clipped - 6 lines]
> 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-
[quoted text clipped - 32 lines]
>
> }
Ben Voigt [C++ MVP] - 20 Aug 2007 18:42 GMT
> 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"?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.