Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subclass class in PRG file
Message
From
21/06/2018 11:03:36
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01660806
Message ID:
01660807
Views:
86
>Hi,
>
>I have a class defined in a prg file (e.g. MyClass.prg). I need to subclass it so that I can replace the code in one of the methods with my custom code.
>
>How do you do it?
>
>TIA

Dmitry,

At the time of the subclass definition, the upper class must be in scope by a SET PROCEDURE TO MyClass.prg. You must create a new prg (assuming you don't want to change the original one) in which you just redefine what needs to be changed.

For instance, this being MyClass.prg
DEFINE CLASS SomeClass AS Custom

  FUNCTION Method_One
    LPARAMETERS Parm1 AS Number, Parm2 AS Number
    RETURN m.Parm1 * m.Parm2
  ENDFUNC

  FUNCTION Method_Two
    LPARAMETERS Parm1 AS Number, Parm2 AS Number
    RETURN m.Parm1 / m.Parm2
  ENDFUNC

END DEFINE
you may write a different MySubClass.prg with
DEFINE CLASS SomeSubClass AS SomeClass

  FUNCTION Method_Two
    LPARAMETERS Parm1 AS Number, Parm2 AS Number
    RETURN IIF(m.Parm2 = 0, .NULL., m.Parm1 / m.Parm2)
  ENDFUNC

END DEFINE
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform