| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 240 人关注过本帖
标题:写了一段把表单转为程序的代码,请指正
只看楼主 加入收藏
李庆宾
Rank: 1
来 自:河南郑州
等 级:新手上路
帖 子:19
专家分:0
注 册:2019-2-1
结帖率:66.67%
  问题点数:0  回复次数:4   
写了一段把表单转为程序的代码,请指正
************部分需要测试几次手动修改
                    NOTE 此转化注意事项:(当前仍有thisform.SetAll('Anchor',240,'commandbutton') 和.Themes无法设置,;
                    1、对OLE和CUSTOM需要手动处理;
                                        DEFINE CLASS Monthview1X AS olecontrol&&不成功,不能赋值???;
                                        OLECLASS ="MSComCtl2.MonthView.2"              ;
                    2、控件相互调用顺序和加载顺序出现冲突,需要手动调整加Add次序;
                    3、如有变量传递到表单的init事件,需要设置中间性的Public变量,以实现从程序头到init的传递注意释放;
                                        LPARAMETERS cgetpassed;
                                        PUBLIC cToVarGet;
                                        cToVarGet = cgetpassed;
                    4、COLUMN下的控件容易发生重复,原因不名,注意手动消除;
                    5、有些COLUMN的名出现错乱,需要手动调整回和控件名一致。

cFilePathGet = GETFILE("scx")

IF EMPTY(cFilePathGet)
 = MESSAGEBOX("没有选择文件,返回!",0+16,"请选择文件")
RETURN
ENDIF
IF UPPER(JUSTEXT(cFilePathGet)) != "SCX"
 = MESSAGEBOX("选择文件不是所需要转化的表单文,返回!",0+16,"请选择VCX后缀的表单文件")
RETURN
ENDIF
cNameOfForm = JUSTSTEM(cFilePathGet)
IF USED(cNameOfForm)
    USE IN &cNameOfForm
ENDIF
USE &cFilePathGet. IN 0 EXCLUSIVE
SELECT &cNameOfForm
LOCATE FOR class = "form"
cStrFormName = ALLTRIM(&cNameOfForm..Objname)
cStrPro = &cNameOfForm..Properties
cStrPROC = &cNameOfForm..Methods
cAllForms = cStrPro + CHR(13) + cStrPROC
TEXT TO cPrgFileGet TEXTMERGE NOSHOW
PUBLIC <<cNameOfForm>>
<<cNameOfForm>> = NEWOBJECT("<<cStrFormName>>")
<<cNameOfForm>>.Show
RETURN
******************************************************* 一 层 DEFINE__Form
DEFINE CLASS <<cStrFormName>> AS form
ENDTEXT &&大多数表单都有,没有的话可以手动去掉,也可以最后改为判断再加 "creturn" 行

SELECT &cNameOfForm
SET FILTER TO platform = "WINDOWS" AND  UPPER(Parent) = UPPER(cStrFormName)&& AND !INLIST(Baseclass,"custom"),"olecontrol"
COUNT TO nObjInForm
DIMENSION cObjDefinStr(nObjInForm)
nObjNow = 1
SCAN
cPrgFileGet = cPrgFileGet + CHR(13) + "ADD OBJECT " + ALLTRIM(&cNameOfForm..Objname) + " AS " + ALLTRIM(&cNameOfForm..Objname) + "X"
cStrPro = &cNameOfForm..Properties
cStrPROC = &cNameOfForm..Methods
TEXT TO cObjDefinStr(nObjNow) TEXTMERGE NOSHOW
******************************************* 二 层 DEFINE
DEFINE CLASS <<ALLTRIM(Objname)>>X AS <<ALLTRIM(class)>>
<<cStrPro>>
<<cStrPROC>>
ENDTEXT
nObjNow = nObjNow + 1
ENDSCAN
cPrgFileGet = cPrgFileGet + CHR(13) + cAllForms + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13)
FOR i = 1 TO nObjInForm
*!*        IF i = 4
*!*        SET STEP ON
*!*        ENDIF
    DO CASE
    CASE " AS GRID"$UPPER(cObjDefinStr(i))
        nAllinAtGC = ALINES(aGridDivided,cObjDefinStr(i))
        cObjDefinStr(i) = aGridDivided(1) + CHR(13) + aGridDivided(2)
        cAllGrids = ""
        FOR il = 3 TO nAllinAtGC
            IF !"ColumnCount" $ aGridDivided(il)
                cAllGrids = cAllGrids + aGridDivided(il) + CHR(13)
            ENDIF
        ENDFOR
        SELECT &cNameOfForm
        SET FILTER TO UPPER(baseclass) = "GRID"
        GO TOP
*!*            BROWSE
        LOCATE FOR (ALLTRIM(UPPER(Objname)) + "X")$UPPER(cObjDefinStr(i))
        cParrentName = ALLTRIM(UPPER(Objname))
        SET FILTER TO cParrentName$UPPER(Parent)
        COUNT TO nObjInSonClass
        nObjInSonClass = nObjInSonClass/2
        FOR k = 1 TO nObjInSonClass
            cSonMiddleName = "COLUMN" + ALLTRIM(STR(k))
            cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "ADD OBJECT " + cSonMiddleName + " AS " + cParrentName + cSonMiddleName + "X"
        ENDFOR
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + cAllGrids + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13) + CHR(13)
        FOR k = 1 TO nObjInSonClass
        cSonMiddleName = "COLUMN" + ALLTRIM(STR(k))
        cFilterNeedStr = cParrentName + "." + cSonMiddleName
        SELECT &cNameOfForm
        SET FILTER TO cFilterNeedStr$UPPER(Parent)
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "******************************************* 三 层 DEFINE__Grid__Column"
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "DEFINE CLASS " + cParrentName + cSonMiddleName + "X AS COLUMN"
        SCAN
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "ADD OBJECT " + ALLTRIM(&cNameOfForm..Objname) + " AS " + cParrentName + cSonMiddleName + ALLTRIM(&cNameOfForm..Objname) + "X"
        ENDSCAN
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13) + CHR(13)
        SCAN
        cStrPro = &cNameOfForm..Properties
        cStrPROC = &cNameOfForm..Methods
TEXT TO cObjDefinStr(i) TEXTMERGE ADDITIVE NOSHOW
******************************************* 四 层 DEFINE__Column__Son
DEFINE CLASS <<cParrentName + cSonMiddleName + ALLTRIM(Objname)>>X AS <<ALLTRIM(class)>>
<<cStrPro>>
<<cStrPROC>>
ENDTEXT
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13) + CHR(13)
        ENDSCAN
        ENDFOR
        cPrgFileGet = cPrgFileGet + CHR(13) + cObjDefinStr(i)
    CASE UPPER(" AS Container")$UPPER(cObjDefinStr(i))
        nAllinAtGC = ALINES(aGridDivided,cObjDefinStr(i))
        cObjDefinStr(i) = aGridDivided(1) + CHR(13) + aGridDivided(2)
        cAllGrids = ""
        FOR il = 3 TO nAllinAtGC
            cAllGrids = cAllGrids + aGridDivided(il) + CHR(13)
        ENDFOR
        SELECT &cNameOfForm
        SET FILTER TO UPPER(baseclass) = "CONTAINER"
        GO TOP
        LOCATE FOR (ALLTRIM(UPPER(Objname)) + "X")$UPPER(cObjDefinStr(i))
        cParrentName = ALLTRIM(UPPER(Objname))
        SET FILTER TO cParrentName$UPPER(Parent)
        COUNT TO nObjInSonClass
        DIMENSION cObjSonDefinStr(nObjInSonClass)
        nObjSonNow = 1
        SCAN
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + "ADD OBJECT " + ALLTRIM(&cNameOfForm..Objname) + " AS " + cParrentName + ALLTRIM(&cNameOfForm..Objname) + "X"
        cStrPro = &cNameOfForm..Properties
        cStrPROC = &cNameOfForm..Methods
TEXT TO cObjSonDefinStr(nObjSonNow) TEXTMERGE NOSHOW
******************************************* 三 层 DEFINE__Container
DEFINE CLASS <<cParrentName + ALLTRIM(Objname)>>X AS <<ALLTRIM(class)>>
<<cStrPro>>
<<cStrPROC>>
ENDTEXT
        nObjSonNow = nObjSonNow + 1
        ENDSCAN
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + cAllGrids + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13)
        FOR ii = 1 TO nObjInSonClass
        cObjDefinStr(i) = cObjDefinStr(i) + CHR(13) + cObjSonDefinStr(ii) + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13)
        ENDFOR
        cPrgFileGet = cPrgFileGet + CHR(13) + cObjDefinStr(i)

    OTHERWISE
        cPrgFileGet = cPrgFileGet + CHR(13) + cObjDefinStr(i) + CHR(13) + "EndDefine" + CHR(13) + CHR(13) + CHR(13)
    ENDCASE
ENDFOR &&optiongroup没有子层行和column没有本层行,不需要单独生成。只有grid三层和container子层需要要。


USE IN &cNameOfForm


***************************************************整理步骤
nLinesGet = ALINES(aStrLines,cPrgFileGet)
cPrgFileGet = ""
FOR ik = 1 TO nLinesGet
    IF "..\..\"$aStrLines(ik)
    aStrLines(ik) = STRTRAN(ALLTRIM(aStrLines(ik)),"..\..\",'"') + '"'
    ENDIF
    IF "..\"$aStrLines(ik)
    aStrLines(ik) = STRTRAN(ALLTRIM(aStrLines(ik)),"..\",'"') + '"'
    ENDIF
    IF "Color ="$aStrLines(ik) AND !"RGB"$UPPER(aStrLines(ik)) AND ","$aStrLines(ik)
    aStrLines(ik) = STRTRAN(ALLTRIM(aStrLines(ik)),"Color =","Color = RGB(") + ")"
    ENDIF
    IF aStrLines(ik) = "DisplayValue ="
    aStrLines(ik) = "DisplayValue = 0 "
    ENDIF
    IF !EMPTY(aStrLines(ik)) AND RIGHT(aStrLines(ik),7) != "Value ="&&去掉所有空行,和未赋值的空串。
        cPrgFileGet = cPrgFileGet + aStrLines(ik) + CHR(13)
        IF INLIST(UPPER(aStrLines(ik)),"ENDDEFINE","ENDPROC")
            cPrgFileGet = cPrgFileGet + CHR(13) + CHR(13) + CHR(13)
        ENDIF
    ENDIF
ENDFOR

_cliptext = cPrgFileGet

cPathSave = "FXQX_DESIN\PROGRAMS\"
IF !DIRECTORY(cPathSave)
    cPathSave = ADDBS(GETDIR("D:\","选择存放Prg路径……","",2,.T.))
ENDIF
STRTOFILE(cPrgFileGet,cPathSave + cNameOfForm + ".prg",0)
****ERASE  FXQX_DESIN\PROGRAMS\&cNameOfForm..FXP &&删除生成的可运行文件,以便新编可执行文,否则不能及时查验错误。
MODIFY COMMAND &cPathSave.&cNameOfForm..prg NOWAIT  

[此贴子已经被作者于2019-2-4 00:53编辑过]

2019-02-04 00:52
sdta
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:176
帖 子:7506
专家分:17997
注 册:2012-2-5
  得分:0 

坚守VFP最后的阵地
2019-02-04 01:42
gs2536785678
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:237
专家分:654
注 册:2017-7-16
  得分:0 
没有工夫看,你自我欣赏吧。
2019-02-04 07:10
schtg
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:576
专家分:788
注 册:2012-2-29
  得分:0 
回复 楼主 李庆宾
好!谢谢!
2019-02-04 07:37
符fp
Rank: 1
等 级:新手上路
帖 子:6
专家分:4
注 册:2018-12-18
  得分:0 
4 天前 15:01







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050789 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved