We need your input on how to migrate FoxPro forms
Posted: Wed Jan 08, 2020 11:48 am
To all FoxPro users,
We have been studying how we can implement our tool to convert FoxPro forms code to .Net using Windows Forms.
From what we have seen, FoxPro allows you to write Events (Event Handlers) at the control level.
For example if a form has 2 button controls, then each of these buttons can have a Click event
with the code that gets executed when that button is pressed. This click event belongs to the button.
The form on which the buttons are located can also have a click event.
In Windows Forms there are also click events at the form level and the control level, so that looks very much like FoxPro. (On the other hand, Windows Forms controls typically include many dozens of properties and events (for exampleWindows Forms Events ), which is not like FoxPro's compact list).
However, in a normal Windows Forms window, when designed with the Windows Forms editor, the events/ event handles for the form and the events for the controls all become event handlers (methods) at the form level.
We can migrate your VFP form code to Windows Forms fairly easy and we can also migrate the events.
To migrate same named events for different controls and maybe also a same named event at the form we would have to give each of them a unique name. So when your form has OkButton and CancelButton the events would be called something like PROCEDURE OkButton_Click and PROCEDURE CancelButton_Click and PROCDURE Form_Click.
And we would be able to migrate the existing code out of the form into these methods.
For methods that receive parameters we would also be able to send the same parameters to these methods.
So far no problems, however there is one big difference:
Inside VFP in the Click Event for OkButton the variable "this" refers to the control and "thisform" to the form.
When the same code is in an event on the form then "this" is the form and not the control.
If you are using "this" a lot in the button event handlers, then that could be a problem, because you (or we) would have to make a lot of changes.
We could automate that in the conversion and make a local variable "thiscontrol" which points to the control and rename all references from the original code to "this" to "thiscontrol" and then rename all references to "thisform" to "this.
But we are not sure if that would result in a situation that would make everybody happy.
There is another solution to that:
When we detect that you have created an event handler for a control then we can create a subclass of the Button class for the OKButton and another subclass of the Button class for the CancelButton.
The Click event for each button would then be added to the subclass for that button. Conceptually that is not a problem and the code would remain very much like it is in VFP.
Unfortunately the standard Windows Forms editor does not allow us to automatically generate subclasses for controls when events are added.
So that would mean that we would have to use our own "custom" VFP window editor.
Again this is not impossible for us (we have created our own form editor for Visual Objects forms already) but it would be a bit more work for us.
If we would do that then you would have the choice of using the "custom" VFP form editor for existing forms that have been migrated to .Net and then the standard Windows forms editor for new forms.
The differene between the 2 would be (apart from some visual changes of course) that the custom editor automatically generates subclasses for controls with events and moves the event handlers to these subclasses.
And the standard Forms editor would not generate subclasses for controls and event handlers will be placed on the form and named uniquely (usually the control name + event name).
Also with a custom editor we would be able to make it look visually more closer to what the current FoxPro visual editor looks like (including the tabbed approach of the properties window), we would be able to limit the amount of properties/events shown and we will have full control on code generation, to make it look like very similar to existing FoxPro event handling code, without a need for additional code translating from WinForms to FoxPro style code.
Creating a custom editor requires a bit more work on our side but would create a solution that is more familiar to VFP developers. Of course it would be still possible to use the standard VS Windows Forms editor for adding new forms to existing or new projects, and both types of windows can be included in the same running application with no issues.
We really would like your input on this. To simplify the above to 3 questions:
1) Are you using "this" a lot in your event handlers ?
2) Would it be a problem for you if we change "this" to "thiscontrol" for event handlers (and then "this" becomes the same as "thisform")
3) If this is a problem, do you think it would be a good idea to have a special form editor and automatically generate subclasses to solve this problem ?
We are anxious to hear your input on this.
The X# devteam
We have been studying how we can implement our tool to convert FoxPro forms code to .Net using Windows Forms.
From what we have seen, FoxPro allows you to write Events (Event Handlers) at the control level.
For example if a form has 2 button controls, then each of these buttons can have a Click event
with the code that gets executed when that button is pressed. This click event belongs to the button.
The form on which the buttons are located can also have a click event.
In Windows Forms there are also click events at the form level and the control level, so that looks very much like FoxPro. (On the other hand, Windows Forms controls typically include many dozens of properties and events (for exampleWindows Forms Events ), which is not like FoxPro's compact list).
However, in a normal Windows Forms window, when designed with the Windows Forms editor, the events/ event handles for the form and the events for the controls all become event handlers (methods) at the form level.
We can migrate your VFP form code to Windows Forms fairly easy and we can also migrate the events.
To migrate same named events for different controls and maybe also a same named event at the form we would have to give each of them a unique name. So when your form has OkButton and CancelButton the events would be called something like PROCEDURE OkButton_Click and PROCEDURE CancelButton_Click and PROCDURE Form_Click.
And we would be able to migrate the existing code out of the form into these methods.
For methods that receive parameters we would also be able to send the same parameters to these methods.
So far no problems, however there is one big difference:
Inside VFP in the Click Event for OkButton the variable "this" refers to the control and "thisform" to the form.
When the same code is in an event on the form then "this" is the form and not the control.
If you are using "this" a lot in the button event handlers, then that could be a problem, because you (or we) would have to make a lot of changes.
We could automate that in the conversion and make a local variable "thiscontrol" which points to the control and rename all references from the original code to "this" to "thiscontrol" and then rename all references to "thisform" to "this.
But we are not sure if that would result in a situation that would make everybody happy.
There is another solution to that:
When we detect that you have created an event handler for a control then we can create a subclass of the Button class for the OKButton and another subclass of the Button class for the CancelButton.
The Click event for each button would then be added to the subclass for that button. Conceptually that is not a problem and the code would remain very much like it is in VFP.
Unfortunately the standard Windows Forms editor does not allow us to automatically generate subclasses for controls when events are added.
So that would mean that we would have to use our own "custom" VFP window editor.
Again this is not impossible for us (we have created our own form editor for Visual Objects forms already) but it would be a bit more work for us.
If we would do that then you would have the choice of using the "custom" VFP form editor for existing forms that have been migrated to .Net and then the standard Windows forms editor for new forms.
The differene between the 2 would be (apart from some visual changes of course) that the custom editor automatically generates subclasses for controls with events and moves the event handlers to these subclasses.
And the standard Forms editor would not generate subclasses for controls and event handlers will be placed on the form and named uniquely (usually the control name + event name).
Also with a custom editor we would be able to make it look visually more closer to what the current FoxPro visual editor looks like (including the tabbed approach of the properties window), we would be able to limit the amount of properties/events shown and we will have full control on code generation, to make it look like very similar to existing FoxPro event handling code, without a need for additional code translating from WinForms to FoxPro style code.
Creating a custom editor requires a bit more work on our side but would create a solution that is more familiar to VFP developers. Of course it would be still possible to use the standard VS Windows Forms editor for adding new forms to existing or new projects, and both types of windows can be included in the same running application with no issues.
We really would like your input on this. To simplify the above to 3 questions:
1) Are you using "this" a lot in your event handlers ?
2) Would it be a problem for you if we change "this" to "thiscontrol" for event handlers (and then "this" becomes the same as "thisform")
3) If this is a problem, do you think it would be a good idea to have a special form editor and automatically generate subclasses to solve this problem ?
We are anxious to hear your input on this.
The X# devteam