Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subclass class in PRG file
Message
 
 
To
21/06/2018 12:39:18
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01660806
Message ID:
01660811
Views:
52
>>Hi Antonio,
>>
>>If I may ask you a follow up question, please.
>>
>>The class that I am creating, by subclassing, will be used in a Form. And the custom method that will have "my" code will have a reference to the form (e.g. thisform.) Which causes the error.
>>How do I use this subclassed object in the Form so that the custom method would be able to reference the Thisform?
>>
>>UPDATE: I think I need to instantiate the class in the INIT of this method using NewObject().
>
>Dmitry
>
>For an object - of any class - to be able to address the form using the Thisform reference, it must be part of the form (that is, it must be contained by the form). If you try to instantiate it during Init, it won't be a form object unless you add it to the form (AddObject() instead of NewObject()).
>
>You may try the different results by changing the values of the #DEFINEs at the beginning.
>
>
>#DEFINE	AS_A_FORM_OBJECT	.T.
>#DEFINE	ADD_AT_INIT			.F.
>
>LOCAL Test AS DF
>
>m.Test = CREATEOBJECT("DF")
>m.Test.Show(1)
>
>DEFINE CLASS DF AS Form
>
>	ADD OBJECT ClickMe AS CommandButton WITH Caption = "Click me!"
>
>#IF AS_A_FORM_OBJECT
>
>	#IF !ADD_AT_INIT
>
>	ADD OBJECT SaySomething AS X
>
>	#ELSE
>
>	FUNCTION Init
>		This.AddObject("SaySomething", "X")
>	ENDFUNC
>
>	#ENDIF
>
>#ELSE
>
>	SaySomething = .NULL.
>
>	FUNCTION Init
>		This.SaySomething = NEWOBJECT("X")
>	ENDFUNC
>#ENDIF
>
>	FUNCTION ClickMe.Click
>		Thisform.SaySomething.MethodOne()
>	ENDFUNC
>
>ENDDEFINE
>
>DEFINE CLASS X AS Custom
>
>	FUNCTION MethodOne
>		Thisform.Caption = "Hola @ " + TTOC(DATETIME(), 2)
>	ENDFUNC
>
>ENDDEFINE
>
>
>Of course, one could argue if your subclass shouldn't be looking for a form in its class hierarchy, and only issue Thisform when it found one.

Thank you, Antonio. For now I will leave the code with "thisform" in a method of this class (since it works). But when time permits I will see if I can review/change this. Just FYI, this is a class that connects to FTP for a file download. And the form has a progress bar. So the class (via updatebuffer method) calls the progress bar to update and show the progress.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform