fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

code disappearing 13 May 2020 15:43 #14553

  • Kevin Clark's Avatar

  • Kevin Clark

  • Topic Author


  • Posts: 74
  • 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
    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.

    Please Log in or Create an account to join the conversation.

    code disappearing 13 May 2020 17:48 #14557

  • Chris's Avatar

  • Chris


  • Posts: 2128
  • 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.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    code disappearing 13 May 2020 17:56 #14559

  • Chris's Avatar

  • Chris


  • Posts: 2128
  • 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.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    code disappearing 13 May 2020 18:58 #14563

  • Kevin Clark's Avatar

  • Kevin Clark

  • Topic Author


  • Posts: 74
  • 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
    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.

    Please Log in or Create an account to join the conversation.

    code disappearing 13 May 2020 20:04 #14565

  • Chris's Avatar

  • Chris


  • Posts: 2128
  • 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.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    code disappearing 13 May 2020 20:10 #14566

  • FFF's Avatar

  • FFF


  • Posts: 1008
  • Well, the old dogma, paint in one file, inherit in another and code there, holds true...
    Regards
    Karl (X# 2.6; Xide 1.26; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF.

    code disappearing 13 May 2020 21:22 #14567

  • Kevin Clark's Avatar

  • Kevin Clark

  • Topic Author


  • Posts: 74
  • Thanks, Chris. Putting the code into a separate file does seem to resolve the problem.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1