The program below generates  code to demonstrate 1000 levels of inheritance of VFP objects. The code looks like this:

 

DEFINE CLASS c1 as c2

ENDDEFINE

 

DEFINE CLASS c2 as c3

ENDDEFINE

 

DEFINE CLASS c3 as c4

ENDDEFINE

 

 

That means class “c1” is a subclass of class “c2”, etc. On my machine, 1000 levels of inheritance run almost instantaneously. Try adding more levels and you’ll run into some limitations.

 

There are a few different kinds of limitations that you can hit, depending on how you modify the code sample. One is the Thread Stack size for each thread of the process. Another is VFP’s STACKSIZE

If you change the baseclass to be a Form, then you’ll run into a GDI limit on the number of windows created. On my machine the RegisterDragDrop call fails. I don’t get an error dialog, because there are too many windows already created!

 

 

 

CLEAR ALL

CLEAR

 

SET TEXTMERGE ON  TO temp.prg noshow

NLEV=1000

      \NUM=1000

      \CLEAR

      \DIMENSION x[NUM]

      \ns=SECONDS()

      \FOR j = 1 TO NUM

      \     x[j]=CREATEOBJECT("c1")

      \ENDFOR

      \x[NUM].Foobar("param")

      \?SECONDS()-ns

      FOR i = 1 TO NLEV

            \DEFINE CLASS c<<i>> as c<<i+1>>

            \ENDDEFINE

            \

      ENDFOR

     

      \DEFINE CLASS c<<NLEV+1>> as custom

      \     PROCEDURE Foobar(p1)

      \           ?PROGRAM(),this.baseclass,this.name

      \ENDDEFINE

     

     

SET TEXTMERGE to

 

*?FILETOSTR("temp.prg")

COMPILE temp

MODIFY COMMAND temp nowait