Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Plugins & AF

Hello again,

In the dummy arrangement below lets say the user clicks a menu item to load a particular measurement type. The menu item tag contains the name of the class that it needs to load.  So it calls the Load Class Default Value function which returns an LV Object type.  It then casts it to the actual data type using the To More Specific Class function, before then launching the actor.

This all works but it means if I have 30 different classes they will all have to have class constants sitting within the case structure and therefore all the classes will be loaded into memory when the main program starts.  This is not ideal as a user on any one occasion may only need to load one or two plugins.

I have avoided this problem in the past when not using the AF, but I can't figure out how to avoid it when I am using it.  Can anybody offer any advice please?

Thank you,

Martin

eg.PNG

0 Kudos
Message 1 of 8
(4,965 Views)

I have not done much with plugins, however it seems to me you can just cast to Actor.lvclass and run the Launch Actor.vi, right? Any initialization will have to occur in Pre-launch Init or Actor Core though.

0 Kudos
Message 2 of 8
(3,580 Views)

The thing is the actual type seems to be lost if I do that; I had tried casting it to a mySuperWidget ancestor class.  But then when I call Launch Actor it tires to launch an instance of mySuperWidget not the actual child class myWidget.

0 Kudos
Message 3 of 8
(3,580 Views)

Casting it to Actor.lvclass should work, the actual type should not be lost.

If you try to cast to a type that failes, it the cast node will return default data for the type that you tried to cast it to. So I'm guessing what happened when you previously tried it is the cast failed, then you launched actor on the default data for mySuperWidget. Wire your error wire through and see if I'm right.

The cast will fail if myWidget.lvclass is not a child of mySuperWidget.

0 Kudos
Message 4 of 8
(3,580 Views)

<Cringe> Yes it works fine, as usual it is me being a monkey...I made a mistake in a subvi that meant the actual type was lost.

Thanks for the speedy help, its much appeciated as always.

Martin

0 Kudos
Message 5 of 8
(3,580 Views)

Let's start with one basic misunderstanding. In the picture you've shown, delete the case structure. Wire the parent class of all of those classes to the middle terminal of the To More Specific node. It is *exactly* the same functionality. The To More Specific node DOES NOT CARE about the value on the wire, only about the wire type.

Once you delete that case structure, you won't have all those classes in memory.

You will need to pass in an absolute path instead of a relative path to the Get LV Class Default Instance.vi.

0 Kudos
Message 6 of 8
(3,580 Views)

PS: The Preserve Run-Time Class primitive is the one that cares about the actual object on the wire. But you don't need to use that here.

0 Kudos
Message 7 of 8
(3,580 Views)

Here's a refresher course if you need it:

http://vishots.com/005-visv-labview-class-factory-pattern/

Message 8 of 8
(3,580 Views)