Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create Object from Class With All Properties/Methods
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00541381
Message ID:
00541792
Vues:
22
Hi!

Understand now.

>Since it was forwarded to me, I would say yes, that would work, but it is a workaround for something different. Renoir wanted to create the exact copy of his combobox class at runtime with all custom PEMs without using the class itself, not create a combination of combobox and another hooked class defined in PRG. The custom methods for the exact copy of the class still cannot be created at runtime without using a defined class itself.
>
>>Hi!
>>
>>Despite Nancy did given you great tip, I'll try to jump in with my @0.02...
>>
>>Really, in the run-time you CAN define the new method for object in the memory. Only thing that you cannot do in run-time, is definition of the _Access and _Assign methods for properties. To assign code to method in run-time, you require to have PRG with DEFINE CLASS like following:
>>
>>
>>DEFINE CLASS MyHook as Custom && or whatever - does not matter
>>oHookedObject = &pcObjectRef
>>... && list of properties in form oHookedObject.PropertyName
>>procedure oHookedObject.Valid
>>...
>>endproc
>>...
>>ENDDEFINE
>>
>>
>>You will see that code between 'procedure oHookedObject.Valid' and 'endproc' pretty well runs on Valid event of the object reference to which assigned as character string into the pcObjectRef variavle before MyHook class creating and adding to the form or any container of the form with any name...
>>
>>
>>Well, you can do this all in run-time for your combobox, however, as Nancy said, it is much better to use the class.
>>
>>
>>Finally, I see no reason to make a copy of class either way. Why not make a new class based on the old class, but just override the functionality using pure OOP? to override certain event functionality at all, in the new class just put '*' in the code window (comment). This will override the parent class method code, but default behavior will work anyway. If you want to add your own functionality, add your code and put 'dodefault()' somewhere in the code if you're sure parent class have code in this method/event. You can add any property or hide existing property by making it private in the child class. Whatever you want. I prefer this approach because it is pure OOP and code reusability. What if you want to add certain new functionality to your combobox class? you will have to do that for all copies. When you have parent/child classes, you add that functionality to parent class, and it applies to every child class.
>>
>>HTH and good luck!
>>
>>
>>
>>
>>
>>>>But you cannot add the custom methods (if you need them) to the instance of the default VFP class and can add the custom properties only at runtime with AddProperty method.
>>>
>>>Ahhh... I got it. So, if I ever need an object that has custom properties or methods I must create a class and an instance. I wonder why? Seems like it would be handy for a couple reasons. First just to have it without the class link if you needed it, and second so the object could be tested fully then saved as a class if it was needed elsewhere. Oh, well... Thanks Nick!
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform