Jump to content
ensegre

list children classes?

Recommended Posts

How can I, given a parent class object, get programmatically an array of names of its direct children? The information is available in the class Hierarchy view, so I thought that some secret vi buried in vi.lib/Utility/LVClass or such might have come to play, but found none.

TIA, Enrico

Share this post


Link to post
Share on other sites

I know nothing about the internals of LabVIEW on this one, but would be a bit surprised if the parents knew about their children, it is more likely to be the other way around surely?

 

At runtime you can inject new child classes, so surely this means the parent must have zero knowledge of children?

Share this post


Link to post
Share on other sites

At runtime you can inject new child classes,

off topic and bear me for my ignorance, but how do you do that in LV? Plugin libraries (which I never confronted with)?

Anyway, even in that situation, wouldn't it still be meaningful to ask the list of currently known children?

Share this post


Link to post
Share on other sites

I think we're talking about edit-time information, not run-time, right?

 

Parents knowing about their children at run-time sounds wrong.

Share this post


Link to post
Share on other sites

Why exactly does your class need to know about existing ancestors at run-time?  It sounds like a design problem, not a code problem.

Share this post


Link to post
Share on other sites

It may well be. Suppose I have a class Devices to which I add incrementally (coding more, plugins are yet over my head) children drivers for specific instruments. I want to display a list of those implemented so far / offer the user to choose which instrument to use for a task among those available, and such.

Share this post


Link to post
Share on other sites

Well if you don't have a plug-in architecture working yet (which would be one way to solve his problem) you need to have your classes included statically somewhere in your code.

 

Why not make an array of your implemented classes and simply call an "ID" method on them returning their IDs which may or may not be different from their names on disk.

 

How are you managing all of your different classes at the moment within your program?

Share this post


Link to post
Share on other sites

Well if you don't have a plug-in architecture working yet (which would be one way to solve his problem) you need to have your classes included statically somewhere in your code.

 

Why not make an array of your implemented classes and simply call an "ID" method on them returning their IDs which may or may not be different from their names on disk.

 

Precisely what I did. Not even an ID method, just Get LV Class Name.vi for now, but that's the idea. I thought there must have been a smarter way, like this I would have to maintain the static array every time I create a new class.

 

[Ok, the question was purely academic: I have so far just three such classes and they are not supposed to increase any soon. Even.]

 

 

How are you managing all of your different classes at the moment within your program?

In what sense managing?

Share this post


Link to post
Share on other sites

I meant managing in the sense of "how does your program know when to use which class?".

 

Given the absence of a factory pattern, you will NEED to have this array maintained statically.  These are essentially the two options available.  One is static, the other is dynamic.

Share this post


Link to post
Share on other sites

I meant managing in the sense of "how does your program know when to use which class?".

 

Picking the desired element of that static array.

 

I guess I need to educate myself more about the factory pattern in future. Thx for the answer!

Share this post


Link to post
Share on other sites

Impressed. I remark that 1 gives only first children, while 2 all descendants. At least with a 3 generation hierarchy of mine which I tested.

Share this post


Link to post
Share on other sites

As for your other question about plugins, theres a few links I'll put below but you should ask yourself these questions:

Do you really need to do this?

...I mean really, are you sure?

......No really, its not fun.

 

Ok so if you really do decide to do this, theres a few things that would come in handy:

https://ekerry.wordpress.com/2012/01/24/created-single-file-object-oriented-plugins-for-use-with-a-labview-executable/

https://decibel.ni.com/content/groups/large-labview-application-development/blog/2011/05/08/an-approach-to-managing-plugins-in-a-labview-application

https://decibel.ni.com/content/docs/DOC-21441

 

Depending on how many plugins you have and how many platforms you need to support and how many labview versions you support (Versions*OS*plugins=lots??) you should look into using a build server like jenkins.

 

Finally, as for the actual code you might find this handy

https://github.com/NISystemsEngineering/CEF/tree/master/Trunk/Configuration%20Framework/class%20discovery%20singleton

its an FGV which locates plugins on disk or in memory, removes duplicates and allows you to load classes by an unqualified or qualified name (assuming they're unique). Its not particularly complex but it provides all the little wrapper functions we needed.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.