Is it possible to add the “Thisform” keyword to the foxpro dialect of X#?

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

Post Reply
User avatar
xinjie
Posts: 127
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

Is it possible to add the “Thisform” keyword to the foxpro dialect of X#?

Post by xinjie »

Hi, Robert

I thought of this when I was using the foxpro dialect of X#.

“This” stands for the class/class instance itself and ‘Thisform’ stands for the form in VFP.
But in X# there is no such difference.

We can assume a scenario:
You have a custom class, and in the class method definition, you need to dynamically add a control to the form at runtime when an action is performed.
Then the class instance is added to the form at the moment of design. Because the object hierarchy of forms and class instances is full of variables, if you use “This.Parent.Parent......” this way, it is still a relatively complex piece of code assuming that this can be accomplished.
Everything would be simpler if the existence of “Thisform".
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
kevclark64
Posts: 128
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Re: Is it possible to add the “Thisform” keyword to the foxpro dialect of X#?

Post by kevclark64 »

I second this. "Thisform" is extremely handy when you are using custom classes and you want to reference a property or method of the form on which the class is located. As you say, you can do the parent.parent.parent route but that becomes very complex, especially when a class could be used on various levels of a form. Also, Foxpro programmers are accustomed to "Thisform" so it would be good to support it just for compatibility.
User avatar
robert
Posts: 4606
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Is it possible to add the “Thisform” keyword to the foxpro dialect of X#?

Post by robert »

Guys,
Event handlers in FoxPro are events of the Control class, in X# they are events of the form class.

In FoxPro, "this" inside an event handler is a reference to the control. This is a bit strange, because strictly speaking, FoxPro does not really generate a subclass for the event, but stores the event with the form. Our converter therefore converts "this" inside an event handler to thisobject.
The alternative would have been to generate a subclass for each control on a form. That could probably work if we had generated our own form designer.
But that would not work with the Windows Form designer from Visual Studio.

After the form was migrated, you can refer to the form itself with simple "this".
Only inside custom control, you can't do that, because "this" is the custom control.
What we can do is declare a "thisform" property that returns the form itself on the form class, and that walks the parent list for a custom control until the form is found.
If you use "this" on the form, then the compiler can check for typos and generate early bound code.
A "thisform" property on the form and custom control class will be declared as object (or usual) and using it will always generate late bound code.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
xinjie
Posts: 127
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

Re: Is it possible to add the “Thisform” keyword to the foxpro dialect of X#?

Post by xinjie »

Robert,

I personally don't see the need for a separate VFP form designer after my short attempt.
Although the property/field/constructor/method signatures are slightly different from VFP, these are easily accepted.

I like the idea of declare a “thisform” property.
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
Post Reply