| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2496 人关注过本帖
标题:写了一段把表单转为程序的代码,请指正
只看楼主 加入收藏
李庆宾
Rank: 1
来 自:河南郑州
等 级:新手上路
帖 子:27
专家分:0
注 册:2019-2-1
结帖率:80%
收藏
 问题点数:0 回复次数:6 
写了一段把表单转为程序的代码,请指正
************部分需要测试几次手动修改
                    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编辑过]

搜索更多相关主题的帖子: 表单 FOR DEFINE CLASS IF 
2019-02-04 00:52
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 

坚守VFP最后的阵地
2019-02-04 01:42
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:0 
没有工夫看,你自我欣赏吧。
2019-02-04 07:10
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1731
专家分:3329
注 册:2012-2-29
收藏
得分:0 
回复 楼主 李庆宾
好!谢谢!
2019-02-04 07:37
符fp
Rank: 2
等 级:论坛游民
威 望:2
帖 子:24
专家分:32
注 册:2018-12-18
收藏
得分:0 
2019-02-12 15:01
丁春秋yxp
Rank: 5Rank: 5
等 级:贵宾
威 望:10
帖 子:248
专家分:310
注 册:2017-10-31
收藏
得分:0 
高人
2019-02-18 12:29
李庆宾
Rank: 1
来 自:河南郑州
等 级:新手上路
帖 子:27
专家分:0
注 册:2019-2-1
收藏
得分:0 
回复 6楼 丁春秋yxp
大神

感谢有大家同行
2019-02-20 20:33
快速回复:写了一段把表单转为程序的代码,请指正
数据加载中...
 
   



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

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