We need your input on how to migrate FoxPro forms

This forum is meant for questions about the Visual FoxPro Language support in X#.

Jun
Posts: 1
Joined: Fri Jan 10, 2020 5:01 am

We need your input on how to migrate FoxPro forms

Post by Jun »

In addition to what others said about this, thisform, this.parent, we also use WITH ... ENDWITH. For instance, this is how I set up one of my grids. These codes are on the Grid's Init event:

Code: Select all

With This
	.RecordSourceType= 1
	.RecordSource='vwADSB'
	.column1.ControlSource='vwADSB.refno'
	.column2.ControlSource='vwADSB.revision'
	.column3.ControlSource='vwADSB.modno'
	.column4.ControlSource='vwADSB.description'
	.column5.ControlSource='vwADSB.issued'
	.column6.ControlSource='vwADSB.adstatus'
	.column7.ControlSource='vwADSB.repetitive'
	.column8.ControlSource='vwADSB.compdue'
	.column9.ControlSource='vwADSB.hrs'
	.column10.ControlSource='vwADSB.hrsdate'
	.column11.ControlSource='vwADSB.comprefno'
	.column12.ControlSource='vwADSB.adsched'
	.column13.ControlSource='vwADSB.tagged'
	.column14.ControlSource='vwADSB.origin'
	.column15.ControlSource='vwADSB.lbk'
	.column13.DynamicCurrentControl = 'IIF(vwadsb.tagged=1,"imgChk","imgnochk")'
	.SetAll('Alignment',2,'Header')
	.SetAll('DynamicBackColor','ICASE(ALLTRIM(vwadsb.description) = "CANCELLED",RGB(255,179,179),'+;
	'INLIST(ALLTRIM(vwadsb.adstatus),"FE","E") AND ALLTRIM(vwadsb.repetitive) = "YES",RGB(0,190,0),'+;
	'INLIST(ALLTRIM(vwadsb.adstatus),"FE","E") AND ALLTRIM(vwadsb.repetitive) = "NO",RGB(183,255,183),'+;
	'RGB(255,255,255))','Column')
	.RowHeight= gomyapp.RowHeight 
ENDWITH


That made it more readable for me than a lot of reference to the same object (This):

Code: Select all

This.RecordSourceType= 1
This.RecordSource='vwADSB'
This.column1.ControlSource='vwADSB.refno'
This.column2.ControlSource='vwADSB.revision'
and so on....
cisberner
Posts: 2
Joined: Fri Jan 10, 2020 6:05 am

We need your input on how to migrate FoxPro forms

Post by cisberner »

1) Are you using "this" a lot in your event handlers ?

Yes, and not only buttons but any other control as well. In most cases I create classes of composite controls with generic code that calls THIS and THIS.Parent. These composite controls can be dropped on a form (in the designer or with lazy instantiation) and can interact with the form through eventbinding (BINDEVENTS(THISFORM.cntInfo,"OnUpdate",THISFORM,"OnUpdateInfo").

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")

I see no problem at all.

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 ?

A custom form editor is a good alternative if point 2) would not be implemented. I stay neutral to this.
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

We need your input on how to migrate FoxPro forms

Post by mainhatten »

robert wrote: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.
Hi Robert,

to avoid writing another of my too-long answers, I'll try to answer in 3 separate posts, this one the easiest.
As you were unaware of vfp9 report engine in vfp source already availabel, let me point out a few options for analyzing/porting existing GUI code.
In the xCode of vfp there is the Class Browser, written by Marcus Egger IIRC. That version has an option to write out vfp .prg code for any vcx-based class loaded into Class Browser. The original version had 1 or 2 small bugs which made direct reuse of the generated code impossible - but AFAIK the versions on vfpX fixed those bugs, so that the prg-code returned form Class Browser is runnable code. Probably easier to target only 1 (.prg) based conversion - although you could go the other way, load prg based GUI and save each element in vcx via WriteAsClass.

I don't know if you are aware of Lianja, which is another system supporting vfp dialect. Lianja has a porting tool for vcx/scx files, creating corresponding .prg files for the whole library. As classes inherited or aggregated on forms most of the times point to superclasses in same or different vcx, this eases identifying precursor classes. I was involved for a few months and rewrote said porting tool from 3-4K by Barry Mavin (lead dev of Lianja) able to handle some classes to current state (12-13K) handling all classes and the special fields in vcx governing new and overwritten methods and properties. This version is still active today and the only problem surfaced recently was a call to also ported Beautifier, which I had to added ease comparison directly or via Source Control (probably pathig to defsult settings...).
I think the whole resulting source was/is Open Sourced, but feel better if Barry was contacted and asked in advance, as initial start of the code came from his fingertips ;-)
If really needed, I could probably recreate his starting point as white-room development. If you download Lianja evaluation, latest porting tool should be included.

About a dozen years ago I wrote a tool creating Python object code from all vfp properties - used that to create a WPF GUI via Ironpython from vfp forms running as hidden COM - similar to FoxInCloud building HTML forms running across the Internet of vfp server side code for local clients running WPF GUI equivalent to the vfp form. Probably not useful in your surroundings - but with tiny changes could write out JSON trees of vfp forms for wholesale debugging effort. I retained rights to the basic feasability proof (but would have to search on old DAT-tapes ...), further dev was made and sold as closed source.

Hope you find some of the above helpful

Thomas
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

We need your input on how to migrate FoxPro forms

Post by kevclark64 »

I use "this" and "thisform" all the time. I also use "parent" occasionally and also "bindevents", but that's infrequent enough that manually making a change to those items would be pretty simple. Also, as Matt pointed out, there are lots of times when I will use something like "pageframe1,page1,pageframe1.page2.button1".

I like the idea of changing "this" to "thiscontrol". I also like the idea of putting all the event handlers in one place like VB.NET does. I've always considered the fact that FoxPro breaks up events into discrete parts linked to objects to be a drawback, not a good feature. Using both VB.NET and Foxpro, I find the VB.NET model much more convenient.
User avatar
KoenPiller
Posts: 1
Joined: Thu Mar 21, 2019 10:49 pm

We need your input on how to migrate FoxPro forms

Post by KoenPiller »

Hi,
There is almost not any piece of code which makes use of This and or ThisForm, a typical piece of code is:
With This
.Combo1.Clear()
For liMonth = 1 To 13
.iaMonths[m.liMonth, 2] = Gomonth(.idCurrentmonth, (-6 + (m.liMonth - 1)))
li1stShowMonth = MONTH(.iaMonths[m.liMonth, 2])
lcMonth = Alltrim(This.GetFormatedDate(.iaMonths[m.liMonth,2], LOCALE_USER_DEFAULTMONTH, "MMMM"))
.iaMonths(m.liMonth,1) = m.lcMonth
.Combo1.AddItem( m.lcMonth )
.Combo1.List[.Combo1.NewIndex,2] = Transform(m.liMonth)
Endfor
.Combo1.Value = .Combo1.List(1)
Endwith

or
With Thisform

.SetCaptions()
.cLogfile = m.tcLogfile
.edtError.Value = Filetostr( .cLogfile)

Endwith

2)if you change this to thiscontrol, no problem but it should not be the same as thisform
3)if ness why not, I would not prefer since this again another layer
Koen
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

We need your input on how to migrate FoxPro forms

Post by Chris »

Hi Koen & everyone,

For this particular matter, it is not important for us if you actually use the identifier itself or through a With statement, the important thing is if it is a very common practice to refer to the control directly while handling one of its events, or it is more common to refer to controls through "thisform" (with or without a "With").

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!"

Of course if we choose this path, we would not require from you to change manually all your 100s of thousands of lines of code, a tool would do this automatically. And after the application is ported, new code would follow the new pattern.

Please do not take the above as set in stone at all, it is only a suggestion, as we are trying to find the correct balance for the best way to implement things. Depending on your input we may end up implementing this in an even more VFP compatible way, or we may end up providing more than one solutions... In any case, thank you very much to everyone that has replied so far, your responses are very valuable, please keep them coming!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

We need your input on how to migrate FoxPro forms

Post by mainhatten »

robert wrote: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.
Yes, the form will "house" any event code written for controls aggregated on the form. But IIRC that is not a special feature of the form, but of ANY container which has a child control aggreagated, as an "object instance" is aggregated, not a class where properties and methods can be overwritten at the class level. This will result in method names duplicating the object name path from the outermost container.
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.
OkButton can be added to a form many times, as long as it is always surrounded by another container - inside each container the names must be unique, NOT for total form.

Code: Select all

MyForm.Pgf1.PageEntry.OkButton
MyForm.Pgf1.PageMiddle.Container.OkButton
MyForm.Pgf1.PageLast.ContainerBottom.CmdGroup.OkButton
MyForm.Pgf2.PageMain.CmdGroup.OkButton
is valid vfp structure having all that IN THE SAME FORM - which would not be ok for WinFroms IIRC. I think a naming convention like "MyForm#Pgf1#PageLast#ContainerBottom#CmdGroup#OkButton#click()" for vfp# might be safest, as it sidesteps the already overused dot (object path, namespaces) in Dotnet.
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.
Count me among those unhappy with such a solution.
CAVEAT EMPTOR: the following is only my mental model, NOT verified debugging vfp runtime at C-level
Some OOP languages have explicit pointers to current/housing object (think Python self as first method parameter or the JS gymnastics with apply, bind and call), others just hide the self reference. I envisioned vfp method call to always follow the pattern of

Code: Select all

procedure MyMethod(Hidden_Implicit ThisForm, Hidden_Implicit This, OtherParameters)
Of course a hidden property with an access method walking the way up container hierarchy to next containing form or set during addobject() would also work, but "Parent" is a property, "ThisForm" not.
"ThisControl" is palatable (portable code via preprocessor in vfp), "ThisForm" exchanged with "This" not.
Better to add a "__ThisForm" property to each control and mangle "ThisForm" on the vfp# side via preprocessor into a call to "ThisControl.__ThisForm" for those methods defined at the control class level.
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.
I cannot visualize that idea totally - but include complex controls added in already multiple times overwritten event delegate each called via dodefault() early in your testing. Gut twitches here that you might have to add a stack of events as a single object might be in trouble or not be enough.
It has been too long since reading about the option to (re)name variables to keywords with leading @ - back when I first read about it, I tought it was probably used to switch IL "this" to IronPython "self", but never looked hard. Perhaps that way the "This" of Winform event could be mapped into "Thisform" and the "ThisControl" into "This" in the event method ?
[snipped part of custom editor]
I dislike the idea of a custom editor - alternative POV in 3. post...
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 ?
Yes
2a) Would it be a problem for you if we change "this" to "thiscontrol" for event handlers
No
2B) Would it be a problem for you if ( then "this" becomes the same as "thisform")
YES
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 ?
No, I think creating a special Winform editor is not the best solution - next post, but have to order thoughts first...

regards
thomas
atlopes
Posts: 83
Joined: Sat Sep 07, 2019 11:43 am
Location: Portugal

We need your input on how to migrate FoxPro forms

Post by atlopes »

Chris asked:
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!"
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.

Code: Select all

DEFINE CLASS SensitiveButton AS CommandButton

  PROCEDURE Click
     This.Caption = "Ouch! I got clicked!"
  ENDPROC

ENDDEF
atlopes
Posts: 83
Joined: Sat Sep 07, 2019 11:43 am
Location: Portugal

We need your input on how to migrate FoxPro forms

Post by atlopes »

Robert asked
1) Are you using "this" a lot in your event handlers ?
As all others said, a lot. To put some numbers on the table, the current project that I have opened right now, "This" as a reference to an object, is used 9909 times in 88 files, so it's a big deal.

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")
"This" is used in every kind of object, not only those that can be placed in a form. For me, it would be a real nuisance, but in a less personal tone and thinking of all the VFP documentation that it exists, starting by the incredible help file that supports us, this change (pun intended) would be a major blow. And I didn't mention the code.

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 ?
If you can generate subclasses of arbitrary subclasses at any level of class hierarchy... But I confess I'm not able to assess the difficulty and implications of the task and certainly would be too dumb to say if it's a good idea or not.
cisberner
Posts: 2
Joined: Fri Jan 10, 2020 6:05 am

We need your input on how to migrate FoxPro forms

Post by cisberner »

Good idea to talk numbers:
My largest project does mention THIS in 113000 cases in 750 files.My smaller projects mention THIS in 41000 cases in 170 files.
Post Reply