code disappearing

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

code disappearing

Post by kevclark64 »

I'm having a problem with code disappearing from a form's PRG file if I make any change to the form in the design window. This happens if I add an object or change a property of an object on the form.

I can reproduce the error by doing the following using Visual Studio 2019 16.5.5 and the 2.4a release of X#:

1) create a new Windows forms project
2) place a button on the form
3) double click the button to get to the form code
4) paste the following code into the button's click method

Code: Select all

local tmpfilename as string
            //tmpfilename=GETFILE("VCX","Select a VCX file to read","Select",0,"Select VCX file")
            openFileDialog1.DefaultExt="VCX"
            openFileDialog1.Title="Select a VCX file to read"
            openFileDialog1.ShowDialog()
            tmpfilename=openFileDialog1.FileName
            IF NOT EMPTY(tmpfilename) then
                txtFileName.text=tmpfilename
                showclasses()
            ELSE
                thisform.lblFileName.caption=""
            ENDIF 

5. Go to the design window and change a property of the button (I've been adding "tag" to the tag property but I think any property change would work)
6. Go back to the code window. On my computer, everything between the line "tmpfilename=openFileDialog1.FileName" and "END CLASS" is now gone.
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

code disappearing

Post by Chris »

Hi Kevin,

Thanks, confirmed, apparently the designer has trouble reading the keywords NOT and THEN. Until this is fixed, please for now use ".NOT." instead of "NOT" and completely remove "THEN".

Note: Please use this only as a temporary workaround. We do understand that it is important that those keywords are properly supported in the FoxPro X# dialect.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

code disappearing

Post by Chris »

Hi Kevin,

Actually, I cannot reproduce this in the FoxPro dialect, but only in Core. Have you set the project to use FoxPro dialect, in the project options window? You need to do this anyway, because otherwise the compiler will not understand the FoxPro syntax, same with the VS form designer.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

code disappearing

Post by kevclark64 »

The steps that I posted earlier was my attempt to reproduce the error as simply as possible. For the program in which I first discovered this problem the dialect is set to FoxPro and the form has several other controls on it. In the original program where I found the error, the button_click code didn't disappear but code later on in the file disappeared. The complete program is

Code: Select all

USING System
USING System.Collections.Generic
USING System.ComponentModel
USING System.Data
USING System.Drawing
USING System.Linq
USING System.Text
USING System.Threading.Tasks
USING System.Windows.Forms
BEGIN NAMESPACE classconvert
    PUBLIC PARTIAL CLASS Form1 ;
        INHERIT System.Windows.Forms.Form
        PUBLIC CONSTRUCTOR()   STRICT//Form1
            InitializeComponent()
            RETURN
            
    PRIVATE METHOD button1_Click(sender AS OBJECT, e AS System.EventArgs) AS VOID STRICT
            local tmpfilename as string
            //tmpfilename=GETFILE("VCX","Select a VCX file to read","Select",0,"Select VCX file")
            openFileDialog1.DefaultExt="VCX"
            openFileDialog1.Title="Select a VCX file to read"
            openFileDialog1.ShowDialog()
            tmpfilename=openFileDialog1.FileName
            IF NOT EMPTY(tmpfilename) then
                txtFileName.text=tmpfilename
                showclasses()
            ELSE
                thisform.lblFileName.caption=""
            ENDIF 
    RETURN
    
    private method showclasses
        select 0
        use (txtFileName.text) alias vcxfile
        if RecCount()<1 then
            MessageBox.Show("There are no classes in this file.")
            RETURN
        endIF
        select vcxfile
        scan
            if Val(vcxfile.reserved2)=1 then
                lstClasses.Items.Add(vcxfile.objname,true)
            endif 
        endscan
    RETURN

    END CLASS 
END NAMESPACE
In this program, with the dialect set to Foxpro, all the code between "private method showclasses" and "END CLASS" disappears. The code disappearance happens whether or not THEN and/or .NOT. is used. However, with the steps I originally posted I do get the same results as you (no code disappearance) when the dialect is set to Foxpro.
User avatar
Chris
Posts: 4584
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

code disappearing

Post by Chris »

Thanks Kevin, I can also see the problem, apparently the parser has trouble with SELECT, USE and I am sure other commands as well.

Until this is fixed, I think the best way to workaround this problem is to add your code that the parser has trouble with in a separate .prg file than the form prg. So, in this particular case, define the PARTIAL class also in another prg and move in there the showclasses() METHOD. That should take care of this for now.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
FFF
Posts: 1532
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

code disappearing

Post by FFF »

Well, the old dogma, paint in one file, inherit in another and code there, holds true...
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

code disappearing

Post by kevclark64 »

Thanks, Chris. Putting the code into a separate file does seem to resolve the problem.
Post Reply