Questions about class definitions in the Visual FoxPro dialect

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

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

Questions about class definitions in the Visual FoxPro dialect

Post by xinjie »

Hi,

I've reviewed the discussions on this board related to the problem, read the help documentation (probably not all of it), and actually added a class file in the VS IDE (in a console project for learning). Ultimately, I have two questions:

1 I don't see the As clause of the DEFINE CLASS command in the class definition added via the template. I tried to follow the classic VFP approach of using “This.” somewhere inside the class definition in an attempt to learn its base class through intellisense. According to VFP, is its base class the Object class in .NET ?

2 I have successfully derived a second class in the same project based on the first X# class created (Visual FoxPro dialect). Although I haven't based the class on a class in some namespace that compiles with X#, I'm fairly certain it can be done. But I am confused when I want to create class definitions based on .NET. Is it because I haven't properly tried the beliefs I'm sure of or is it simply not possible?

=============================
I have a personal media platform on the internet in China called “Subscription Account”. I have the temerity to keep posting X# related topics so that Chinese VFP programmers can get a closer look at it, and even Chinese .NET programmers can get what they might want to know from it. Below are links to the two collections for interested programmers in other countries. Of course, they are in simplified Chinese, which I'm sure should be understandable by using any of the online translation methods.

https://mp.weixin.qq.com/mp/appmsgalbum ... t_redirect

https://mp.weixin.qq.com/mp/appmsgalbum ... t_redirect
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Questions about class definitions in the Visual FoxPro dialect

Post by robert »

Xinjie,
The template does not have the AS Clause, but you can of course use that clause.
The big difference between X# (.Net) and FoxPro is that you can decide yourself from which class you want to inherit.
In FoxPro all classes must eventually inherit from one of the FoxPro classes like "Custom". In .Net you can choose to inherit from nothing, which means that you'll inherit from the class Object in the System namespace (aka System.Object).
If you use the /fox1 compiler option, then the compiler will automatically let classes inherit from Custom when there is no AS ParentClass clause.
The VFP compatible Custom class is in the XSharp.VFP namespace, so its full name is XSharp.VFP.Custom.

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

Re: Questions about class definitions in the Visual FoxPro dialect

Post by xinjie »

Hi,Robert

Other questions: How are classes created in X# using the Visual FoxPro dialect significantly different from classes in VFP (sorry, I'm stuck with VFP terminology for now) in terms of events or methods?
Last edited by xinjie on Mon May 13, 2024 7:42 am, edited 1 time in total.
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
Chris
Posts: 4845
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Questions about class definitions in the Visual FoxPro dialect

Post by Chris »

Hi,

That should be easy, what error message did you get?

Try a simple

Code: Select all

DEFINE CLASS Test AS System.Collections.ArrayList
ENDDEFINE
that should work already.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Questions about class definitions in the Visual FoxPro dialect

Post by robert »

Xinjie,

Some differences between .Net and VFP:

- .Net has Fields and Properties. VFP calls everything Properties
- In VFP methods that are called when an event is happening are called Events. In .Net these 'Event Handlers' are just methods. Technically, there is no difference between a method that is called from an event and a normal method
- In .Net an Event is a separate member type in a class. You can create your own events, and elsewhere in your code you can subscribe to these events.

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

Re: Questions about class definitions in the Visual FoxPro dialect

Post by xinjie »

Hi, Chris

I'm sorry, I just realized I seem to be able to do this. Thank you very much!
Chris wrote: Mon May 13, 2024 7:40 am Hi,

That should be easy, what error message did you get?

Try a simple

Code: Select all

DEFINE CLASS Test AS System.Collections.ArrayList
ENDDEFINE
that should work already.
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
xinjie
Posts: 98
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

Re: Questions about class definitions in the Visual FoxPro dialect

Post by xinjie »

Hi, Robert

I may have some problems expressing myself in English.

I would like to know if in the .NET world, or in X#, classes have a similar problem as VFP's “order of events”. If so, what is the best way for me to learn about it?
robert wrote: Mon May 13, 2024 7:45 am Xinjie,

Some differences between .Net and VFP:

- .Net has Fields and Properties. VFP calls everything Properties
- In VFP methods that are called when an event is happening are called Events. In .Net these 'Event Handlers' are just methods. Technically, there is no difference between a method that is called from an event and a normal method
- In .Net an Event is a separate member type in a class. You can create your own events, and elsewhere in your code you can subscribe to these events.

Robert
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Questions about class definitions in the Visual FoxPro dialect

Post by robert »

Xinjie,

I do not understand what you mean with problem as VFP's “order of events”

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

Re: Questions about class definitions in the Visual FoxPro dialect

Post by xinjie »

hi,Robert

This is explained in detail in the VFP Help file:

https://www.vfphelp.com/help/_5wn12p98c.htm

This should be considered a demo, but it's relatively “big” :

https://www.vfphelp.com/help/_5WN12P991.htm

Simply put, if you emit “Thisform.Release” from the button of a VFP form, then, just for the form, the following “events” will occur in sequence as it closes: Destroy() and Unload()

What I mean is that in the .NET world, or in X#, for that matter, a class instance also automatically triggers some events in order when it is destroyed ?

robert wrote: Mon May 13, 2024 8:36 am Xinjie,

I do not understand what you mean with problem as VFP's “order of events”

Robert
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Questions about class definitions in the Visual FoxPro dialect

Post by robert »

Xinjie,

Ok, I see. You are referring to the specific events for VFP forms.
Our implementation of the VFP compatible forms, which is based on Windows Forms, also calls these event handlers, and we have tried to call them in the same order as VFP. I am sure that there are places where we got it wrong. We'll have to correct those.

The mechanism that we are using may look a bit strange, but the Windows Forms event handlers are expected to have a certain signature. For example the Click event of a control needs to have an object parameter and an EventArgs parameter and a return type of void.
Click Event handlers in FoxPro code have no parameters and an undefined return type. We register an event handler with the proper signature and call the VFP compatible from there.
Another difference is that in VFP the event handlers appear to be at the control level, where .Net has all these events at the form level.

Fabrice can explain this all when needed.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply