Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Opposite of
Message
From
05/09/2006 16:39:45
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
05/09/2006 10:38:29
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Miscellaneous
Thread ID:
01150809
Message ID:
01151096
Views:
41
>>Opposite of "save as class":
>>
>>If I have an object on a form, I can convert it to a class with the command "Save as Class".
>>
>>Is there a way to do this the other way, convert a class to an object on the form? I know I can place an instance of a class, but in this case I want to use the object in one single form, and eliminate the class.
>>
>>The class is inherited from some custom class. Right now, I am creating an instance of the custom class on the form, and manually copying the PEMs. I was thinking there should be a faster way, but there doesn't seem to be.
>
>You may need to write a little builder. Place an instance of the parent class of your object on the form, and get a variable refering to it via aSelObj(). Open your custom class for editing and get another variable refering to it. Now get all the nondefault PEMs for it (via aMembers(), I think "UC" would be the proper third parameter), and then loop through the array it got you, copying PEMs from the second object into the first:
>
>objOnForm.AddProperty("pemname", getpem(obj2, "pemname"))
>
>For methods, instead of .AddProperty use .WriteMethod, but beware: as Nad.. Naomi said, it won't work for new methods that the parent class didn't have. They will be written into your object, but they'll be lost when you save your form. You may want to add them as abstract methods to the parent class before you start this.

Thanks you. It seems there is no "simple opposite" of "Save as Class" - and now I see the reason (complications with the extra properties and methods); I'll research into making a builder - eventually.

In case you are interested, my situation is this: I created hundreds of text reports / Excel reports, using a custom class (basically, download #9991), and created separate classes in a library "report.vcx", before it struck me that I could also include the objects directly on the form. I also realized already that this "new" approach has its limitations; I would still require a class separate from the form if I wanted to a) Use custom properties and methods (unless I move them to the form level), b) use a hierarchy of inheritance (except for the last level, which might reside on the form), or c) invoke the same report class from more than one form.

The main reason I want to integrate the classes into the forms is for organizational purposes - having the report class as an object of the form makes it easier to find the class. Also, if I delete the form (or rather, move it to folder "Obsolete"), the class will be deleted with it.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform