define class MyRoom as container add object "Detector" as MyShape procedure Detector.click wait window "You clicked me!" endproc enddefineor
define class MyRoom as container Detector = createobject("MyShape") procedure Detector.click wait window "You clicked me!" endproc enddefineIt is called 'Late binding' and it is possible for VFP objects only.
>do form main >for i=1 to 5 && to put 5 object on the form, named Room1 to Room5 > main.addobject("Room"+alltrim(str(i)), "MyRoom") >endfor > >define class MyRoom as container > add object "Detector" as MyShape > > procedure Detector.click > wait window "You clicked me!" > endproc >enddefine > >define class MyShape as shape > procedure init > with this > .borderstyle=0 > .backstyle=0 > endwith > endproc >enddefine >>
>define class MyRoom as container > procedure Init > this.addobject("Detector", "MyShape") > endproc > > procedure Detector.click > wait window "You clicked me!" > endproc >enddefine > >define class MyShape as shape > procedure init > with this > .borderstyle=0 > .backstyle=0 > endwith > endproc >enddefine >>
>define class MyRoom as container > add object "Detector" as MyShape >enddefine > >define class MyShape as shape > procedure init > with this > .borderstyle=0 > .backstyle=0 > endwith > endproc > > procedure this.click > wait window "You clicked me!" > endproc >enddefine >>