菜单中的THISFORM(Visual FoxPro)



我们在ProLan(编程语言)主题中的项目是创建一个FoxPro版本的记事本。我的表单看起来已经与记事本完美地相同。我已经完成了菜单栏。现在我的问题是如何访问我的 ThisForm.edit1.Value(我可以在其中键入或查看我的文本的编辑框)到我的菜单程序。因为有一个错误说 THISFORM 应该在方法中。

这是一个我想更改的示例块代码,但仍然不知道如何更改。

PROCEDURE proc_Save
cMessage = ALLTRIM(ThisForm.Edit1.Value)
cFile = GETFILE('Txt:TXT', 'Enter File:', 'Open', 0, 'Open files') && contains the complete path for your file
gnErrFile = FCREATE(cFile)
IF gnErrFile < 0
    WAIT 'Cannot open or create out[ut file' WINDOW NOWAIT
ELSE
    = FWRITE(gnErrFile, cMessage)
ENDIF
= FCLOSE(gnErrFile)
IF gnErrFile = 0
    MESSAGEBOX("File saved.", 64, "Saved")
    ENDIF
cMessage = "" 

上面的代码显示了我的"保存"菜单弹出窗口的代码,但是每次我要单击"保存"时,它都会返回一个错误。此代码在命令按钮中运行良好。但是由于我使用的是菜单程序(命令应该在弹出菜单中),因此我无法访问编辑框。

无论如何,这是我的完整源代码。唯一的错误是带有 THISFORM.edit1.Value 的行。

LPARAMETERS oFormRef, getMenuName, lUniquePopups, parm4, parm5, parm6, parm7, parm8, parm9  
LOCAL cMenuName, nTotPops, a_menupops, cTypeParm2, cSaveFormName  
IF TYPE("m.oFormRef") # 'O' OR ;  
    LOWER(m.oFormRef.BaseClass) # 'form' OR ;  
    m.oFormRef.ShowWindow # 2  
    MESSAGEBOX("Error")  
            RETURN  
ENDIF  
m.cTypeParm2 = TYPE("m.getMenuName")  
m.cMenuName = SYS(2015)  
m.cSaveFormName = m.oFormRef.Name  
IF m.cTypeParm2 = "C" OR (m.cTypeParm2 = "L" AND m.getMenuName)  
    m.oFormRef.Name = m.cMenuName  
ENDIF
IF m.cTypeParm2 = "C" AND !EMPTY(m.getMenuName)
    m.cMenuName = m.getMenuName
ENDIF
DIMENSION a_menupops[3]
IF TYPE ("m.lUniquePopups")="L" AND m.lUniquePopups
    FOR nTotPops = 1 TO ALEN(a_menupops)
            a_menupops[m.nTotPops] = SYS(2015)
    ENDFOR
ELSE
    a_menupops[1] = "file"
    a_menupops[2] = "edit"
    a_menupops[3] = "help"
ENDIF
DEFINE MENU (m.cMenuName) IN (m.oFormRef.Name) BAR
DEFINE PAD mpFile OF (m.cMenuName) PROMPT "<File" COLOR SCHEME 3 ;
    KEY ALT+F, ""
DEFINE PAD mpEdit OF (m.cMenuName) PROMPT "<Edit" COLOR SCHEME 3 ;
    KEY ALT+E, ""
DEFINE PAD mpHelp OF (m.cMenuName) PROMPT "<Help" COLOR SCHEME 3 ;
    KEY ALT+W, ""
ON PAD mpFile OF (m.cMenuName) ACTIVATE POPUP (a_menupops[1])
ON PAD mpEdit OF (m.cMenuName) ACTIVATE POPUP (a_menupops[2])
ON PAD mpHelp OF (m.cMenuName) ACTIVATE POPUP (a_menupops[3])
DEFINE POPUP (a_menupops[1]) MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF (a_menupops[1]) PROMPT "<New" ;
    KEY CTRL+N, "Ctrl+N"
DEFINE BAR 2 OF (a_menupops[1]) PROMPT "<Open...";
    KEY CTRL+O, "Ctrl+O"
DEFINE BAR 3 OF (a_menupops[1]) PROMPT "<Save" ;
    KEY CTRL+S, "Ctrl+S"
DEFINE BAR 4 OF (a_menupops[1]) PROMPT "-"
DEFINE BAR 5 OF (a_menupops[1]) PROMPT "E<xit"
ON SELECTION BAR 1 OF (a_menupops[1]) ;
    DO proc_New
ON SELECTION BAR 2 OF (a_menupops[1]) ;
    DO proc_Open
ON SELECTION BAR 3 OF (a_menupops[1]) ;
    DO proc_Save
ON SELECTION BAR 5 OF (a_menupops[1]) QUIT
DEFINE POPUP (a_menupops[2]) MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR _med_cut OF (a_menupops[2]) PROMPT "Cu<t" ;
    KEY CTRL+X, "Ctrl+X" ;
    MESSAGE "Removes the selection and places it onto the Clipboard."
DEFINE BAR _med_copy OF (a_menupops[2]) PROMPT "<Copy" ;
    KEY CTRL+C, "Ctrl+C" ;
    MESSAGE "Copies the Selection onto the Clipboard."
DEFINE BAR _med_paste OF (a_menupops[2]) PROMPT "<Paste" ;    
    KEY CTRL+V, "Ctrl+V" ;
    MESSAGE "Paste the contents on the Clipboard."
DEFINE BAR 6 OF (a_menupops[2]) PROMPT "-"
DEFINE BAR 7 OF (a_menupops[2]) PROMPT "Select <All" ;
    KEY CTRL+A, "Ctrl+A" ;
    MESSAGE "Selects all items on this page."
DEFINE POPUP (a_menupops[3]) MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 8 OF (a_menupops[3]) PROMPT "<View Help" ;
    KEY CTRL+H, "Ctrl+H"
DEFINE BAR 9 OF (a_menupops[3]) PROMPT "-"
DEFINE BAR 10 OF (a_menupops[3]) PROMPT "<About Notepad" ;
    KEY CTRL+A, "Ctrl+A"

ACTIVATE MENU (m.cMenuName) NOWAIT
IF m.cTypeParm2 = "C"
    m.getMenuName = m.cMenuName
    m.oFormRef.Name = m.cSaveFormName
ENDIF

PROCEDURE proc_New
    cMessage = ALLTRIM(ThisForm.Edit1.Value)
    cFile = GETFILE('Txt:TXT', 'Enter File:', 'Open', 0, 'Open files')
    gnErrFile = FCREATE(cFile)
    IF gnErrFile < 0
            WAIT 'Cannot open or create out[ut file' WINDOW NOWAIT
    ELSE
            = FWRITE(gnErrFile, cMessage)
    ENDIF
            = FCLOSE(gnErrFile)
    IF gnErrFile = 0
    MESSAGEBOX("File saved.", 64, "Saved")
            ENDIF
    cMessage = ""
PROCEDURE proc_Open
    LOCAL cFile
    cFile = ""
    cFile = GETFILE('Txt:TXT', 'Enter File:', 'Open', 0, 'Open files')
    DO CASE
            CASE ".txt" $ LOWER(cFile) && checks if path has a ".txt" string
                    WAIT WINDOW "opening file..." NOWAIT
                            LOCAL gnFileHandle, nSize
                            gnFileHandle = FOPEN(cFile) 
                            nSize = FSEEK(gnFileHandle, 0, 2) 
                            IF nSize <= 0
                                    MESSAGEBOX("This file is empty.", 64, "Message")
                            ELSE
                                    = FSEEK(gnFileHandle, 0, 0)
                                    cMessage = FREAD(gnFileHandle, nSize) 
                                    ThisForm.edit1.Value = ALLTRIM(cMessage)
                            ENDIF
                                    = FCLOSE(gnFileHandle)
                            WAIT CLEAR
            OTHERWISE
                    MESSAGEBOX("Error please choose a valid text file.", 16, "Error")
    ENDCASE
PROCEDURE proc_Save
    cMessage = ALLTRIM(ThisForm.Edit1.Value)
    cFile = GETFILE('Txt:TXT', 'Enter File:', 'Open', 0, 'Open files') 
    gnErrFile = FCREATE(cFile)
    IF gnErrFile < 0
            WAIT 'Cannot open or create out[ut file' WINDOW NOWAIT
    ELSE
            = FWRITE(gnErrFile, cMessage)
    ENDIF
    = FCLOSE(gnErrFile)
    IF gnErrFile = 0
            MESSAGEBOX("File saved.", 64, "Saved")
            ENDIF
    cMessage = ""    

在菜单中,请使用 _SCREEN,而不是 ThisForm。活动表单。

或者,正如 Tamar 提到的,使用另一个变量......在这种情况下,我会在这种情况下以您的形式'Init() 方法做一些事情,例如

if not pemstatus( _Screen, "myNotePadForm", 5 )
   _Screen.AddProperty( "myNotePadForm" )
endif 
_Screen.myNotePadForm = THISFORM

然后,在您的菜单中使用可以做

_Screen.myNotePadForm.whatEver....

这样,您无需担心是否启动了另一个辅助表单并且IT成为"ActiveForm"

相关内容

  • 没有找到相关文章

最新更新