dim container with it's title?

Is it possible to dim a container with its name? Something like this:
dim theScrollingContainerRow as new CLASSBYTITLE(“LineItemContainer”)?

I’m showing invoice line items in different ways for different products. The database has a text field to know how it should be displayed so I know which Container to use. So, I’d like to be able to dim the Container using the name rather than have to dim every single container in the method.

create a dictionary of containers keyed by their name?

That’s a neat idea Dave. Wouldn’t I need to pre dim them for that?

Nothing like Cocoa’s ClassforName or Javas similar counter part

But there are ways

  1. the dictionary dave mentioned - but the dictionary is full of delegates that create new instances
    so you look up the “value” in the dictionary and invoke the “value” - since its a method that creates a new instance
    you still have to set this up & maintain it
    personally I’d not do this as its a lot more maintenance work (you have to set up the dictionary & delegates)

  2. make a module that behaves as a factory that you pass a name and it gives you back a new instance
    in there you can use a select case or a dictionary etc to know which one to return
    again you have to maintain this

The IDE of course has to do this when it loads a project & we use something more like the second approach

Thanks Norm!

Option 2 sounds reasonable, but I’d prefer ClassForName thing… Would that be a weird thing to add to Xojo?

Dim dct As New Xojo.Core.Dictionary() dct.Value("MyContainerName1") = GetTypeInfo(MyContainerName1) dct.Value("MyContainerName2") = GetTypeInfo(MyContainerName2) dct.Value("MyContainerName3") = GetTypeInfo(MyContainerName3) ... Dim ti As TypeInfo = dct.Value(aStringWithOneOfTheContainerNames) Dim cis() As ConstructorInfo = ti.Constructors() Dim ci As ConstructorInfo = cis(0) Dim cc As ContainerControl = ci.Invoke()

Wow! That’s awesome Eli. I’ll try it out and report back!

[quote=277507:@Hal Gumbert]Thanks Norm!

Option 2 sounds reasonable, but I’d prefer ClassForName thing… Would that be a weird thing to add to Xojo?[/quote]
Yes
Why ?
Because we strip out classes that are “not used”.
And what does “not used” mean ?
If theres no property of that type, no ISA checks for that type, no “new” of that type then the class would be stripped

And its possible that you compose “the name” programmatically (concatenate strings, retrieve it from a database, etc) in a fashion that there is NO possibility the compiler could know that it cannot or should not strip the class

So you have to refer to the class somewhere in code to keep it from being stripped
And there are many ways to do that

That makes sense Norman. I didn’t think about classes being stripped out. Eli’s example will work super close to having “ClassforName”!

Xojo rocks.