在运行时通过字符串名称(动态)调用方法? [英] call methods via a string name (dynamically) at runtime?
问题描述
我需要迭代一组控件并设置事件处理程序
使用给定控件的名称作为基础。伪代码
(wishful-thinkingcode!):
AddHandler BufControl.validateevent,AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name& ;_Validate)
假设BufControl = txtAdd1,我要找的替代输出是*:
AddHandler txtAdd1.ValidateEvent, AddressOf txtAdd1_Validate
''TheMagicalFunction ...'的真实姓名是什么,好吗?我前几天刚看到一个帖子
但我没有机会找到它,因为我不知道任何
合法关键字!
谢谢! =)
------------
(*是的,我意识到这段代码永远不会真正出现在源文件中。 -
i只是将它列为最终输出''应该表现得像''的一个例子。
i need to iterate through a collection of controls and set event handlers
using the given control''s name as a basis. in pseudocode
(wishful-thinkingcode!):
AddHandler BufControl.validateevent, AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name & "_Validate")
assume BufControl = txtAdd1, the substituted output i am looking for is*:
AddHandler txtAdd1.ValidateEvent, AddressOf txtAdd1_Validate
what is the real name of ''TheMagicalFunction...'', please? i just saw a post
on this the other day but i have no chance of finding it as i don''t know any
legitimate keywords!
THANKS! =)
------------
(*yes, i realize this code would never actually appear in the source file. -
i just list it as an example of what the final output ''should behave like'')
推荐答案
嗯好吧我发现了我以为我在寻找的东西,CallByName。
但是如何让它与AddHandler配合使用?
谢谢! =)
" K.十二" < KS ***** @ spamAtYourOwnRisk.yahoo.com>在消息中写道
新闻:eW ************** @ TK2MSFTNGP10.phx.gbl ...
hmm ok well i found what i thought i was looking for, "CallByName".
but how do i get it to work with AddHandler?
THANKS! =)
"K. Shier" <ks*****@spamAtYourOwnRisk.yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
我需要迭代一组控件和设置事件处理程序
使用给定控件的名称作为基础。在伪代码中
(如意思维!):
AddHandler BufControl.validateevent,AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name&
" _Validate")
AddHandler txtAdd1.ValidateEvent,AddressOf txtAdd1_Validate
'TheMagicalFunction的真实姓名是什么。 ..'', 请?我前几天刚看到一个
的帖子,但我没有机会找到它,因为我不知道
任何合法的关键字!
感谢! =)
------------
(*是的,我意识到这段代码永远不会出现在源
文件中。 - 我只是列举它作为最终输出''应该表现为
喜欢''的例子。
i need to iterate through a collection of controls and set event handlers
using the given control''s name as a basis. in pseudocode
(wishful-thinkingcode!):
AddHandler BufControl.validateevent, AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name & "_Validate")
assume BufControl = txtAdd1, the substituted output i am looking for is*:
AddHandler txtAdd1.ValidateEvent, AddressOf txtAdd1_Validate
what is the real name of ''TheMagicalFunction...'', please? i just saw a post on this the other day but i have no chance of finding it as i don''t know any legitimate keywords!
THANKS! =)
------------
(*yes, i realize this code would never actually appear in the source file. - i just list it as an example of what the final output ''should behave like'')
我想你指的是到CallByName方法,这不是你想要的
。
-
HTH,
- Tom Spink,überGeek
请回复新闻组,
所以所有人都可以受益
System.Reflection Master"
====转换为2002 ====
删除内联声明
" K.十二" < KS ***** @ spamAtYourOwnRisk.yahoo.com>在消息中写道
新闻:eW ************** @ TK2MSFTNGP10.phx.gbl ...
Hi, I think you''re referring to the CallByName method, which is not exactly
what you want.
--
HTH,
-- Tom Spink, über Geek
Please respond to the newsgroup,
so all can benefit
" System.Reflection Master "
==== Converting to 2002 ====
Remove inline declarations
"K. Shier" <ks*****@spamAtYourOwnRisk.yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
我需要迭代一组控件和设置事件处理程序
使用给定控件的名称作为基础。在伪代码中
(如意思维!):
AddHandler BufControl.validateevent,AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name&
" _Validate")
AddHandler txtAdd1.ValidateEvent,AddressOf txtAdd1_Validate
'TheMagicalFunction的真实姓名是什么。 ..'', 请?我前几天刚看到一个
的帖子,但我没有机会找到它,因为我不知道
任何合法的关键字!
感谢! =)
------------
(*是的,我意识到这段代码永远不会出现在源
文件中。 - 我只是列举它作为最终输出'应该表现为
之类的'''的例子。
i need to iterate through a collection of controls and set event handlers
using the given control''s name as a basis. in pseudocode
(wishful-thinkingcode!):
AddHandler BufControl.validateevent, AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name & "_Validate")
assume BufControl = txtAdd1, the substituted output i am looking for is*:
AddHandler txtAdd1.ValidateEvent, AddressOf txtAdd1_Validate
what is the real name of ''TheMagicalFunction...'', please? i just saw a post on this the other day but i have no chance of finding it as i don''t know any legitimate keywords!
THANKS! =)
------------
(*yes, i realize this code would never actually appear in the source file. - i just list it as an example of what the final output ''should behave like'')
根据你所描述的你可能想要的把反思看成是一个可能的解决方案。
" K.十二" < KS ***** @ spamAtYourOwnRisk.yahoo.com>在消息中写道
新闻:eW ************** @ TK2MSFTNGP10.phx.gbl ...
From what you have described you might want to look at reflection as a
possible solution.
"K. Shier" <ks*****@spamAtYourOwnRisk.yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
我需要迭代一组控件和设置事件处理程序
使用给定控件的名称作为基础。在伪代码中
(如意思维!):
AddHandler BufControl.validateevent,AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name&
" _Validate")
AddHandler txtAdd1.ValidateEvent,AddressOf txtAdd1_Validate
'TheMagicalFunction的真实姓名是什么。 ..'', 请?我前几天刚看到一个
的帖子,但我没有机会找到它,因为我不知道
任何合法的关键字!
感谢! =)
------------
(*是的,我意识到这段代码永远不会出现在源
文件中。 - 我只是列举它作为最终输出''应该表现为
的样子'的例子。)
i need to iterate through a collection of controls and set event handlers
using the given control''s name as a basis. in pseudocode
(wishful-thinkingcode!):
AddHandler BufControl.validateevent, AddressOf
TheMagicalFunctionThatTurnsAStringIntoAMethod(BufC ontrol.Name & "_Validate")
assume BufControl = txtAdd1, the substituted output i am looking for is*:
AddHandler txtAdd1.ValidateEvent, AddressOf txtAdd1_Validate
what is the real name of ''TheMagicalFunction...'', please? i just saw a post on this the other day but i have no chance of finding it as i don''t know any legitimate keywords!
THANKS! =)
------------
(*yes, i realize this code would never actually appear in the source file. - i just list it as an example of what the final output ''should behave like'')
这篇关于在运行时通过字符串名称(动态)调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!