03-29-2007 03:56 PM
I've been experimenting a bit with LabView object oriented programming, bug I can't figure out how to convert/cast an object to a descendent or ancestor class. Specifically, how would I:
1. Convert an object to an object of a descendent class. To carry the examples in the manual a bit further: Let's say I have a generic "Automobile" object, and later discover that the "Automobile" is really a "Ford Model T". How do I cast, convert, or otherwise obtain a "Ford Model T" object which retains all of the original "Automobile" object's private data? (Assuming that my "Ford Model T" class is a descendant of my "Automobile" class.) If I try the "To More Specific Class" function, I get a 1448 error, which I assume is because my "Automobile" object isn't really a "Fort Model T" object and doesn't have all of the private data and methods needed to implement "Ford Model T" object.
2. Convert an object to an object of an ancestor class. Again to expand the examples in the manual, how would I convert my "Ford Model T" object to a generic "Automobile" object, possibly loosing all but the "Automobile" object's private data in the process? This might be useful, for example, if I wanted to preserve the "Automobile" object's private data from my "Ford Model T" object while converting to a class (say "Obsolete Automobile") which is a descendant of "Automobile" but not an ancestor of "Ford Model T"
Thanks, in advance, for your suggestions.
Mark Moss
03-29-2007 04:11 PM
04-17-2007 03:22 PM
But Tom you missed the fact that he is getting errors when casting parent class to child class.
He is using the functions but it isn't letting him as we would expect.
-Norm
04-17-2007 03:33 PM
04-17-2007 03:39 PM
04-17-2007 04:13 PM
04-18-2007 07:50 AM
04-18-2007 09:00 AM
My code is a bit large to post, and I had intended to create a simplified version, but haven't had the time. I think Tomi M's explaination is probably what's happening. Attached a bit of LabView pseudo-code which, I hope, demonstrates what I would like to do.
Since LabView can't change the run-time type of a wire, I suppose the solution to my problem would involve creating a VI which would accept an ancestor object of the object to be created and copy the all of the ancestor's private data to the newly created object. In order to do that, I would need a way to either walk up the class hierarchy copying each class's private data as I go, or somehow access the private data directly. Any ideas?
04-18-2007 09:10 AM
04-18-2007 10:01 AM
Sure (I don't particularly want to go/continue down the wrong path either).
Basically, I have a set of classes which handle file IO for a few file formats we use internally. The class hierarchy is set-up like this, where "Data File.lvclass" provides access to the data and properties in each data-file in a generic manner, while the "On Disk File Format X" classes handle reading/writing that specific file format to/from disk:
Data File.lvclass
On-Disk File Format 1.lvclass
On-Disk File Format 2.lvclass
On-Disk File Format 2 Version 1.lvclass
On-Disk File Format 2 Version 2.lvclass
On-Disk File Format 3.lvclass
etc.
So far, this has worked very well for reading and writing my data-files. Regardless of the format of the file, I can use the same member VI's of "Data File.lvclass" to access/modify the data, get/set properties stored in the file, etc. Where I've run into problems is in attempting to convert the data from one file format to another. For example, I need to read in a file using the "Load" member VI of "On-Disk File Format 1.lvclass", perform a few operations on the file using the methods defined in "Data File.lvclass", and then write the file to disk using the "Save" member VI of "On-Disk File Format 2 Version 2.lvclass".