Using Introspection to get the variable name?

I’ve been looking at Introspection to be able to get the name of a variable but can’t seem to be able to get what I want.
Basically - I just want to inspect the variable name as a string.
I can get all the properties etc but all the ‘name’ properties simply return ‘Picture’

For example - image I have a Picture object called ‘myArt’ in my project. I was hoping to be able to use Introspection to get the name into a variable.

Any clues?


Show us the code you have so far.

Here you go… I basically grabbed a bunch of code from the examples and tried some variations.

Dim theObject As Picture
theObject = myArtPNG

Dim myMethods() As Introspection.MethodInfo =_
For i as Integer = 0 to Ubound(myMethods)
Dim myParameters() as Introspection.ParameterInfo =_
If Ubound(myParameters) > 0 then //if a method has any parameters
For j as Integer=1 to Ubound(myParameters) //loop over the parameters
ListBox1.AddRow myMethods(i).Name
End if

Dim myProperties() as Introspection.PropertyInfo = Introspection.GetType(theObject).GetProperties
For i as Integer=0 to Ubound(myProperties)
ListBox1.AddRow myProperties(i).Name

It sounds like you want to get the name of a Picture that’s been dragged into the project. Introspection will tell you about the parts of a class, but Modules and Project Pictures aren’t available. If your picture is a property of a class you can get the name of the classes property, but not Project Pictures. If this is it perhaps there’s another way; what are you trying to do?

Thanks for the clarification.
I was actually looking for a mechanism be able to switch picture resources for @x2 versions automatically.

Something like;
SourceGraphic = GraphicSelector(myArt)

Where SourceGraphic would end up being myArt of myArt2x depending on it 2x was available.

I’ve a less complicated mechanism that’ll I’ll move to anyway that will load from images in the bundle rather than using already been dragged into the project.

Thanks again

What’s wrong with using

[quote]if retina
draw retinapicture
draw non retinapicture
end if[/quote]

? Or you check out RetinaKit from Sam Rowlands.

Nothing wrong at all. Was just researching an idea.

Thanks all.

This is not possible.

Since myArtPNG is an instance of a class, there is no name for it in the compiled application (like with all variables). One of the solutions is to create a globally accessible dictionary, and mapping the names to the pictures. Something like this:

Module blablabla Public Function Images As Dictionary Static d As Dictionary If d Is Nil Then // This branch is only ever called once d.Value("myArtPNG") = myArtPNG d.Value("myOtherArtPNG") = myOtherArtPNG ... End Return d End Function End Module

Additional note:
Since myArt is an instance of the Picture class, this is superfluous:

Dim theObject As Picture theObject = myArtPNG
You can use myArtPNG in GetType directly:

Dim myMethods() As Introspection.MethodInfo = Introspection.GetType(myArtPNG).GetMethods