We need your input on how to migrate FoxPro forms
Posted: Sun Jan 12, 2020 12:12 pm
Guys, there is absolutely no problem at all using "This" in "regular" code. The only place where it complicates things supporting "This" as a reference to the control in question is in event code, and specifically in automatically generated event code by the visual form editor.
The reason is that the standard Windows Forms form editor generates Click, Mouse, keyboard etc events code as part of the containing form class, so naturally "This" refers to the form itself, not to the control that triggered the event to happen. We can workaround this in a few ways, some of which are:
1) Do not use "This" in event code, instead use a path to the control in question with "Thisfor.Control1.Control2..." instead
2) Use some compiler trickery and possibly some leading code inside the event methods to do the translating between WinForms and VFP style
3) Create a custom Form Designer for ported VFP apps, where we will have full control on what we generate, how and where
But that's only related to using "This" inside event handlers of the visual form designer, this discussion does not affect any other usage of "This" at all. So regarding:
The reason is that the standard Windows Forms form editor generates Click, Mouse, keyboard etc events code as part of the containing form class, so naturally "This" refers to the form itself, not to the control that triggered the event to happen. We can workaround this in a few ways, some of which are:
1) Do not use "This" in event code, instead use a path to the control in question with "Thisfor.Control1.Control2..." instead
2) Use some compiler trickery and possibly some leading code inside the event methods to do the translating between WinForms and VFP style
3) Create a custom Form Designer for ported VFP apps, where we will have full control on what we generate, how and where
But that's only related to using "This" inside event handlers of the visual form designer, this discussion does not affect any other usage of "This" at all. So regarding:
this would still work perfectly fine, completely unmodified from the existing FoxPro version of the code.atlopes wrote:Chris asked:
If I'm getting this right, this would break all of the VFP OOP building because we wouldn't be able to subclass a button to be used in a form or any other container.Another question is, since it is obvious from your replies, that using "this" is very common, would it be acceptable for you to start using only "thisform" from now on in event methods? So, for example the click event code of a command button control that looked like:
This.Caption = "I got clicked!"
would be typed in X# as
Thisform.Button1.Caption = "I got clicked!"Code: Select all
DEFINE CLASS SensitiveButton AS CommandButton PROCEDURE Click This.Caption = "Ouch! I got clicked!" ENDPROC ENDDEF