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

FieldInfo is ok on csarp but not on vb because of WithEvents

What shuld I do on my code to make it work on both vb and csharp(ok). This
code are in a dll

It seems that withevents cause a problem on fieldinfo

private Control getObject(string ControlName)
{
//return an handle of the control
try
{
if(ControlName != FormOwner.Name)
{
BindingFlags bf = BindingFlags.IgnoreCase | BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.GetField;
Type t = FormOwner.GetType();

----- PROBLEM HERE ------
System.Reflection.FieldInfo fi = t.GetField(ControlName,bf)
;------------------------------------
object o = fi.GetValue(FormOwner);
return (Control)o;
}
else
{
return FormOwner;
}
}
catch
{
return null;
}
}

Thank for the help

Nov 15 '05 #1
2 1497
Don't use withevents in vb, add to the event handler as you would in C#.

--
Michael Culley
"Nicolas" <nl*****@hotmail.com> wrote in message news:O8**************@TK2MSFTNGP12.phx.gbl...
What shuld I do on my code to make it work on both vb and csharp(ok). This
code are in a dll

It seems that withevents cause a problem on fieldinfo

private Control getObject(string ControlName)
{
//return an handle of the control
try
{
if(ControlName != FormOwner.Name)
{
BindingFlags bf = BindingFlags.IgnoreCase | BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.GetField;
Type t = FormOwner.GetType();

----- PROBLEM HERE ------
System.Reflection.FieldInfo fi = t.GetField(ControlName,bf)
;------------------------------------
object o = fi.GetValue(FormOwner);
return (Control)o;
}
else
{
return FormOwner;
}
}
catch
{
return null;
}
}

Thank for the help

Nov 15 '05 #2
Yes, It will be good but if an application got hundred or more control then
it become cumberstom to remove all handlers and then add them later on in
the application.

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
Don't use withevents in vb, add to the event handler as you would in C#.

--
Michael Culley
"Nicolas" <nl*****@hotmail.com> wrote in message

news:O8**************@TK2MSFTNGP12.phx.gbl...
What shuld I do on my code to make it work on both vb and csharp(ok). This code are in a dll

It seems that withevents cause a problem on fieldinfo

private Control getObject(string ControlName)
{
//return an handle of the control
try
{
if(ControlName != FormOwner.Name)
{
BindingFlags bf = BindingFlags.IgnoreCase | BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.GetField;
Type t = FormOwner.GetType();

----- PROBLEM HERE ------
System.Reflection.FieldInfo fi = t.GetField(ControlName,bf)
;------------------------------------
object o = fi.GetValue(FormOwner);
return (Control)o;
}
else
{
return FormOwner;
}
}
catch
{
return null;
}
}

Thank for the help


Nov 15 '05 #3

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

Similar topics

2
by: dotnetguy | last post by:
Hello, having a FieldInfo object I'd like to get a reference to the corresponding field object. I know the type of the field object (so I can do a cast if it is required) but I don't know if...
0
by: James Hadwen | last post by:
Hi, I'm trying to do something with reflection that's a little wierd. The idea is that I call for a field to be updated on a base class. Using reflection it first updates the value, and then...
6
by: ORC | last post by:
I will use FieldInfo to import values from a XML file into the fields of an objects. But how to convert to the proper type like in this: public void Load(object MyClass) { foreach( FieldInfo...
0
by: Nicolas | last post by:
How can I fixe my code which is working fine for csarp control but give me trouble on vb control withevents This code is compil in a separate dll private Control getObject(string ControlName) {...
3
by: Laurie | last post by:
Hi, I need to be able to manipulate field values within a structure using FieldInfo.GetValue and FieldInfo.SetValue, in VB.Nt 2003. The GetValue is working fine and makes it really easy for me...
5
by: Dennis | last post by:
I have an array "t" where each element is a structure of type "testing". I want to use the FieldInfo class to set the values of the array element fields. I can read the field properties and...
1
by: David Gouge | last post by:
Posting on behalf of a colleague (no, really! ;) )... Hi, I was wondering if there is any equivalent of FieldInfo.SetValue(Object, Object) that is strongly typed or uses generics? I have been...
7
by: Wilson | last post by:
Hi, How do get the Dictioanry object from FiedlInfo ? my code : fieldInfo = this.GetType().GetField("dictioanry1"); ??Dictionary<string, string> dicTemp1 = (Dictionary<string,...
0
by: kernell | last post by:
Hi everyone, i'm trying to initialize all control of a UserControl to is appropriate class. The value is set but the event won't raise anymore. See the example: 'Not working 'Normally...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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...
1
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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.