473,378 Members | 1,134 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,378 software developers and data experts.

best practice question

Bob
Is there a reasonbly good way to determine what controls will be present in a
class inherited from form, with designer-generated code, without intantiating?

Bob

Nov 20 '05 #1
5 1003
If the class is not instantiated then, as there is no instance of the class,
there will be none.

"Bob" <no*****@nospam.net> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...
Is there a reasonbly good way to determine what controls will be present in a class inherited from form, with designer-generated code, without intantiating?
Bob

Nov 20 '05 #2
Hi Bob,

You can query the Form's Type using Reflection.

Have a play with this:

<code>
Public Sub WhatsInAForm (oFormType As Type)
Dim aF() As FieldInfo
Dim aM() As MemberInfo
Dim Bf As BindingFlags = _
BindingFlags.Instance Or _
BindingFlags.NonPublic Or _
BindingFlags.DeclaredOnly

aF = GetType (oFormType).GetFields (Bf)
Console.WriteLine ("Fields")
For I = 0 To aF.Length - 1
Console.WriteLine ("I = {0} = {1}", I, aF(I).Name)
Next

aM = GetType (oFormType).GetMembers (Bf)
Console.WriteLine ("Members")
For I = 0 To aM.Length - 1
Console.WriteLine ("I = {0} = {1}", I, aM(I).Name)
Next
End Sub
</code>

The BindingFlags are
BF.Instance - Make a FormX to examine.
BF.NonPublic - Controls are Friend, ie. not Public
BF.DeclaredOnly - Skip all the base class stuff.

Regards,
Fergus
Nov 20 '05 #3
Hi Bob,

Two corrections.

I added the Form Type parameter as an afterthought.
You'll need
aF = oFormType.GetFields (Bf)
aM = oFormType.GetMembers (Bf)
instead of
aF = GetType (oFormType).GetFields (Bf)
aM = GetType (oFormType).GetMembers (Bf)

More importantly, this method <does> instantiate the Form. It will call
the constructor though it won't call Form_Load.

Regards,
Fergus
Nov 20 '05 #4
Bob
Now why did I think I couldn't use that to see private members? That works
great, that you. :)

Bob

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:OZ**************@tk2msftngp13.phx.gbl...
Hi Bob,

You can query the Form's Type using Reflection.

Have a play with this:

<code>
Public Sub WhatsInAForm (oFormType As Type)
Dim aF() As FieldInfo
Dim aM() As MemberInfo
Dim Bf As BindingFlags = _
BindingFlags.Instance Or _
BindingFlags.NonPublic Or _
BindingFlags.DeclaredOnly

aF = GetType (oFormType).GetFields (Bf)
Console.WriteLine ("Fields")
For I = 0 To aF.Length - 1
Console.WriteLine ("I = {0} = {1}", I, aF(I).Name)
Next

aM = GetType (oFormType).GetMembers (Bf)
Console.WriteLine ("Members")
For I = 0 To aM.Length - 1
Console.WriteLine ("I = {0} = {1}", I, aM(I).Name)
Next
End Sub
</code>

The BindingFlags are
BF.Instance - Make a FormX to examine.
BF.NonPublic - Controls are Friend, ie. not Public
BF.DeclaredOnly - Skip all the base class stuff.

Regards,
Fergus


Nov 20 '05 #5
What if its full of shared methods? =)
"Stephany Young" <as******@mona.lisa> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
If the class is not instantiated then, as there is no instance of the class, there will be none.

"Bob" <no*****@nospam.net> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...
Is there a reasonbly good way to determine what controls will be present

in a
class inherited from form, with designer-generated code, without

intantiating?

Bob


Nov 20 '05 #6

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

Similar topics

5
by: martin | last post by:
Hi, Is there any best practice guidelines or examples for threadsafe logging? I have to write an auditlogging class for a website. The auditlog will be stored in files on the local filesystem. A...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
4
by: Guy Noir | last post by:
Hello. Is there a pattern or best practice for the following scenario? I have a list of items I would like to compare. The number of items are decided at runtime. ObjectA, ObjectB,...
6
by: AlexT | last post by:
Folks Please bear with me - I'm not a real ASP pro... I need some advice about the following problem: I have "inherited" of a working ASP site which is hosted on a collocated IIS machine. ...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
3
by: cbrown | last post by:
I am rebuilding an existing application that relies on an SQL DB. The app is a scheduling/employee management program. My question pertains to best practices in dotnet and database. I use a 3...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
3
by: Alan Isaac | last post by:
This is a simple question about actual practice. I just want to know how you (yes you) are approaching this problem. The problem: What is the recommended packaging of demo scripts or test...
5
by: Frank Millman | last post by:
Hi all This is not strictly a Python question, but as I am writing in Python, and as I know there are some XML gurus on this list, I hope it is appropriate here. XML-schemas are used to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.