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

Dynamic code compiling and events

Hi all,

Okay, here's something I'd like to do, but I'm not certain its possible.
Thus far in playing with it, I haven't been able to get it going. I'm able
to load and compile a .cs file using the CodeCompiler class. I know that
portion works correctly because I can use the Invoke method of the MethodInfo
object it returns and it triggers my dynamically loaded function. My
problem shows up in +=ing my function onto an event. No matter what I've
tried to give it, I get compiler errors "variable not method", "method name
expected", etc. Is there a way to get this function bound onto my event?
Thanks much!
Nov 16 '05 #1
3 1206
instruo wrote:
Hi all,

Okay, here's something I'd like to do, but I'm not certain its possible.
Thus far in playing with it, I haven't been able to get it going. I'm able
to load and compile a .cs file using the CodeCompiler class. I know that
portion works correctly because I can use the Invoke method of the MethodInfo
object it returns and it triggers my dynamically loaded function. My
problem shows up in +=ing my function onto an event. No matter what I've
tried to give it, I get compiler errors "variable not method", "method name
expected", etc. Is there a way to get this function bound onto my event?
Thanks much!


Have you considered creating a System.Delegate instance?

Frans
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 16 '05 #2
> Have you considered creating a System.Delegate instance?

Frans


I'm not entirely certain what you mean here... naturally I have a delegate
type which my events are based on. Let me explain my setup a bit better:

what I'm doing is implimenting a GUI system using MDX. I have an event
handler delegate and events (MouseDown, Keydown, etc) based on said delegate.
What I'd like to do is be able to += functions compiled from a CodeDom to
said events, effectively giving me a means of scripting my mouse down events
for buttons and the like. My problem is that when I go to do something like
this:

Button.MouseDown += new WidgetEventHandler(...)

I can't find any means of letting it know that its my .GetMethod()'ed
function that I want to use.

I've figured out a work around to this problem, but I'd naturally prefer the
cleaner method of simply binding those function to the events straight up.
Any insight as to how this might be possible, if it is even possible, would
be great. Thanks!
Nov 16 '05 #3
button.GetType().GetEvent("MouseDown").AddHandler( button,
myDynamicMethodDelegate);

Will it do the trick?

HTH,
Alexander Shirshov

"instruo" <in*****@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com...
Have you considered creating a System.Delegate instance?

Frans


I'm not entirely certain what you mean here... naturally I have a
delegate
type which my events are based on. Let me explain my setup a bit better:

what I'm doing is implimenting a GUI system using MDX. I have an event
handler delegate and events (MouseDown, Keydown, etc) based on said
delegate.
What I'd like to do is be able to += functions compiled from a CodeDom to
said events, effectively giving me a means of scripting my mouse down
events
for buttons and the like. My problem is that when I go to do something
like
this:

Button.MouseDown += new WidgetEventHandler(...)

I can't find any means of letting it know that its my .GetMethod()'ed
function that I want to use.

I've figured out a work around to this problem, but I'd naturally prefer
the
cleaner method of simply binding those function to the events straight up.
Any insight as to how this might be possible, if it is even possible,
would
be great. Thanks!

Nov 16 '05 #4

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

Similar topics

1
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
13
by: Chris Thunell | last post by:
I have created several grids dynamically and have added them to different HTML placeholders on a vb.net web form. The grids and controls within them come up and view beautifully when the web page...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
2
by: Ghada Al-Mashaqbeh via DotNetMonster.com | last post by:
Hi all, I am facing a problem in dynamic code generation at run time, the problem occurs when the dynmaic code use global data exist within the original application. Lets say that my...
15
by: EDBrian | last post by:
My problem is this. Our clients create different fields they want to collect and we allow them build dynamic filters, reports etc... We run some TSQL to actually create the column and all works...
8
by: Marc | last post by:
I am studying ASP.NET and have a simple question reading the first lines in this page: http://msdn.microsoft.com/en-us/library/ms366723(VS.80).aspx Are they talking about compilation of C#...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.