GCHandle.Alloc

  • Thread starter Thread starter kresimir ivkovic
  • Start date Start date
K

kresimir ivkovic

Dear all developers

How can I, or can't in command type string of my class ???

for example

Dim gh As GCHandle = GCHandle.Alloc(Me.DCA.Display.XingSize,
GCHandleType.Pinned)

this working good

but I need

Dim gh As GCHandle = GCHandle.Alloc("Me.DCA.Display.XingSize",
GCHandleType.Pinned)



Some idea/suggestion all is good.



Thanx



K.I. System Developer
 
Hi,

This is not related to GCHandle.Alloc at all. You have to present an
object instace to GCHandle.Alloc.

Visual Basic .NET supports late binding also has support for calling
methods by name presented as a string:

http://msdn.microsoft.com/en-us/library/22x2chfx.aspx

As Peter mentioned you also can use reflection that is available to all
the .NET languages.

This XingSize property looks like being of an integer type. If I'm right
then your are most likely trying to do something you don't need. A
GCHandle only makes sense on objects. (You can box an integer into an
object but you most likely don't need a GCHandle for that.)

Kornél
 
Peter said:
That said, as near as I can tell you can't use the CallByName() function
to call static methods, nor does it evaluate anything except the method
name as a string (i.e. the arguments, which is what the OP here is
trying to resolve by string, still have to be fully resolved).

Am I overlooking something?

All of this is correct. CallByName is most likely easier to invoke that
using reflection but reflection is more powerful.

The OP most likely would prefer a VB equivalent of JavaScript eval() but
that's not available in VB. If you or he needs then should use a dynamic
language.

Kornél
 
Back
Top