Hello all,
This is my situation. I'm reading an XML file with a variable number of
nodes.
So far, all of the code has been reasonably easy, but now I'm up against a
wall trying to figure out the best way to proceed.
Upon reading in a valid node, I'm wanting to add a tabpage to a tab control
based on the name value of the node. Since all of the tabpages will have the
same child controls, I customized the tabpage and made a class that uses
tabpage as the base class and put all of the controls I need on it. This
works
great. Everytime I need a new page, I just instantiate a new instance and
add
it to the tab control. The problem now is naming the pages. I thought of an
array, which would be nice, but there won't always be the same number of
valid nodes. Not only that, but the user may want to add more nodes while
working with the files. When a new node is created, it gets it's own
tabpage,
so a fixed array is not a good option. My idea was to just name each tabpage
with the name of the node, but I am having a hard time with that. I did read
up on reflection, and that might be the best way to go, I just don't know
how
to do it. If anyone can help with ideas or other options for doing this, I'd
be
all ears. Alternatively, if someone knows a good article or an example of
how
this is done, please point me to it.
What I need to be able to do is something like:
XmlTabPage <Node.Name> = new XmlTabPage();
where <Node.Name> is the Node's actual text name.
I will be using the Tag property to index and refer to the tabpages, so the
only
time I need to do this is on creation.
Thanks. 5 1163
Gary Morris <gw*******@hotpop.com> wrote:
<snip> What I need to be able to do is something like:
XmlTabPage <Node.Name> = new XmlTabPage(); where <Node.Name> is the Node's actual text name.
I don't see why you actually *do* need to do that. There's no need to
have the actual *variable* with the same name.
I suggest you create the tab page and just put it in a Hashtable, using
the node name as the key.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Gary Morris <gw*******@hotpop.com> wrote:
<snip>
What I need to be able to do is something like:
XmlTabPage <Node.Name> = new XmlTabPage(); where <Node.Name> is the Node's actual text name. I don't see why you actually *do* need to do that. There's no need to have the actual *variable* with the same name.
OK, I don't actually have to have THE node name, I just want some way
of creating each instance of the tabpage with a unique name. Since I've
never had the need to do anything like this, I am looking for any option.
I suggest you create the tab page and just put it in a Hashtable, using the node name as the key.
Never used a hashtable, though I've seen many programs and code
snippets that do use them. Maybe it's time to look into it....???
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Gary Morris <gw*******@hotpop.com> wrote: I don't see why you actually *do* need to do that. There's no need to have the actual *variable* with the same name.
OK, I don't actually have to have THE node name, I just want some way of creating each instance of the tabpage with a unique name. Since I've never had the need to do anything like this, I am looking for any option.
Objects don't necessarily *have* names. Usually I find when people want
to give objects names, they're really after some way of retrieving an
object by a string key later on. That's where hashtables come in
useful. I suggest you create the tab page and just put it in a Hashtable, using the node name as the key.
Never used a hashtable, though I've seen many programs and code snippets that do use them. Maybe it's time to look into it....???
That would be a good idea. I suggest you familiarize yourself with
ArrayLists as well Hashtables before going much further - they're both
pretty fundamental to writing many .NET applications. If you look up
"collection classes" in the MSDN index, you'll see there's a tutorial
and a couple of samples available. I haven't gone through them myself,
but reading them (and/or a Collections chapter in a .NET book) would be
a good idea.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too OK, I don't actually have to have THE node name, I just want some way of creating each instance of the tabpage with a unique name. Since I've never had the need to do anything like this, I am looking for any
option. Objects don't necessarily *have* names. Usually I find when people want to give objects names, they're really after some way of retrieving an object by a string key later on. That's where hashtables come in useful.
What I'm wondering now is, when I create a tabpage will I not need to use
a member variable with the "TabPage somename = new TabPage();" type
of construct? That's what I am hung on. I did notice that I could use the
same "name" in an event (like a button or menu) and it will go ahead and
create a new control without any error, but does that not confuse things
later on? All of the new controls look like clones, so how do I determine
who
is what? How does the program know who is what? I hope that makes sense.
In other words:
You can't say "int i = new int()" but one time in any given scope or the
compiler complains about it and won't compile. Wouldn't the same hold true
for any member? If I have 5 tabpages all created with "TabPage newTab =
new TabPage()" will that actually work? This is what I am hung on more than
anything. I suggest you create the tab page and just put it in a Hashtable,
using the node name as the key.
Never used a hashtable, though I've seen many programs and code snippets that do use them. Maybe it's time to look into it....???
That would be a good idea. I suggest you familiarize yourself with ArrayLists as well Hashtables before going much further - they're both pretty fundamental to writing many .NET applications. If you look up "collection classes" in the MSDN index, you'll see there's a tutorial and a couple of samples available. I haven't gone through them myself, but reading them (and/or a Collections chapter in a .NET book) would be a good idea.
I am familiar with both, just have never used them. I'm sure I've written
code
that would have benefited from one or the other, I just haven't seen the
need
until now!
And thanks for the quick reply. This could mean a good coding job for me if
I
can show that I know what I'm doing (and most of the time I do - I've been
programming since the Commodore, TI-994A, Atari XL, GWBASIC days). It
just sometimes overwhelms me, .NET is so huge.
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Gary Morris <gw*******@hotpop.com> wrote: Objects don't necessarily *have* names. Usually I find when people want to give objects names, they're really after some way of retrieving an object by a string key later on. That's where hashtables come in useful. What I'm wondering now is, when I create a tabpage will I not need to use a member variable with the "TabPage somename = new TabPage();" type of construct? That's what I am hung on. I did notice that I could use the same "name" in an event (like a button or menu) and it will go ahead and create a new control without any error, but does that not confuse things later on? All of the new controls look like clones, so how do I determine who is what? How does the program know who is what? I hope that makes sense.
Just use a local variable. You can reuse that local variable. For
instance:
TabPage foo = new TabPage();
table["somename"] = foo;
foo = new TabPage();
table["someothername"] = foo;
In fact, you can get away without having a variable there at all:
table["somename"] = new TabPage();
table["someothername"] = new TabPage();
In other words: You can't say "int i = new int()" but one time in any given scope or the compiler complains about it and won't compile. Wouldn't the same hold true for any member? If I have 5 tabpages all created with "TabPage newTab = new TabPage()" will that actually work? This is what I am hung on more than anything.
I think you've got fundamental problems in terms of understanding what
a variable is, and its scope. I would stop your current project for the
moment and get back to basics. Unfortunately it's a big topic to
discuss in a newsgroup post - I suggest you read a tutorial or C# book. That would be a good idea. I suggest you familiarize yourself with ArrayLists as well Hashtables before going much further - they're both pretty fundamental to writing many .NET applications. If you look up "collection classes" in the MSDN index, you'll see there's a tutorial and a couple of samples available. I haven't gone through them myself, but reading them (and/or a Collections chapter in a .NET book) would be a good idea.
I am familiar with both, just have never used them. I'm sure I've written code that would have benefited from one or the other, I just haven't seen the need until now!
And thanks for the quick reply. This could mean a good coding job for me if I can show that I know what I'm doing (and most of the time I do - I've been programming since the Commodore, TI-994A, Atari XL, GWBASIC days). It just sometimes overwhelms me, .NET is so huge.
But I still think you need to go back to basics - it's clear there's
some conceptual confusion there which needs clearing up, to be honest.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Frazer |
last post by:
hi
could any one tell me which real life senarios reflection can be used in ?
thnx
|
by: Rachel Suddeth |
last post by:
I'm trying to use reflection to create an object at runtime where the type
is given by a string. I thought we should be able to do that, but so far
it's not working. I'm trying to work on...
|
by: Aaron Queenan |
last post by:
Given the classes:
class Class
{
public static implicit operator int(Class c)
{
return 0;
}
}
class Holder
|
by: Mark |
last post by:
Am I out of my mind if I use Reflection everytime someone logs into our site
to get and track the current Major/Minor/Build/Revision version that the
person is viewing our site through? This...
|
by: Rlrcstr |
last post by:
If I have some code behind a form and I want to be able to pass an object to
it... any of several user defined classes that I have... and then display
the values in the member variables of the...
|
by: HL |
last post by:
The requirement is to send some information to other objects. The objects to
whom the information has to be sent is not available at compile time. The
names of the types (objects) will be provided...
|
by: heddy |
last post by:
I understand that reflection allows me to discover the metadata of a
class at runtime (properties, methods etc). What I don't understand is
where this is useful. For example:
If I am the sole...
|
by: admin |
last post by:
I am trying to get reflection to work and have been spending today
trying to understand it better. I am stuck and hoping someone could
point me in the right direction (maybe a different way of...
|
by: Kuberan Naganathan |
last post by:
Hello all
Does anyone know of a good way to use reflection in c++?
I don't mean simply using rtti or dynamic casting.
I'm talking about java/c# style reflection where an actual instance of...
|
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= |
last post by:
Hi
I am slightly familiar with reflection but have never done the following
I know how to find a class and call but I haven't done the following
The Method return a List of Another Class
And...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |