如何将类库中的类转换为prg中的代码?

问题描述 投票:0回答:1

当类存储在 vcx 库中时,我猜测它没有 DEFINE CLASS 行。如果相同的类存储在 prg 中,它将以 DEFINE CLASS 开头(我认为)。如何从类库(vcx)中获取代码并将其放入 prg 中?您是否只需将 vcx 中的代码复制并粘贴到 prg 中并将 DEFINE CLASS 行添加到其顶部?谢谢

visual-foxpro
1个回答
0
投票

您确实可以从每个 VCX 方法中获取代码,并将其放入 Define

Procedure
/
Endproc
结构内的
Class
/
Endefine
块中。 类的属性可以位于任何位置,通常位于 Define
Class
/
Endefine
的顶部。此外,“视觉”类中还可以有
Control
成员对象,如
Forms
Containers
等。

例如一个简单的表格:

DEFINE CLASS TestForm as Form
    AllowOutput = .F.
    PROCEDURE Init
        LOCAL lnCount
        lnCount = _screen.FormCount
        This.Caption = "TestForm" + TRANSFORM(m.lnCount)
        This.Move(100+m.lnCount*30,m.lnCount*30)
    ENDPROC
ENDDEFINE

或更复杂的内部有

Grid
控件:


LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN

DEFINE CLASS TestForm as Form
    AutoCenter = .T.
    DataSession = 2
    Width = 400
    Height = 300
    
    PROCEDURE Load
        LOCAL i
        CREATE CURSOR temp (col1 L, col2 I, col3 I)
        FOR i = 1 TO 5
            INSERT INTO temp VALUES (.F., i, i * 2)
        ENDFOR
        GO TOP IN temp
    ENDPROC

    ADD OBJECT Grid1 as Grid WITH ;
        Left = 5, Top = 5, Width = 390, Height = 290, Anchor = 15, ;
        RecordSource = 'temp', ColumnCount = 3, ;
        AllowCellSelection = .F., IsCheckBoxClicked = .F.
    
    PROCEDURE Grid1.Init
        WITH This.Column1 as Column
            .AddObject("Check1", "CheckBox")
            .Check1.Caption = ""
            .Check1.BackStyle = 0
            .Check1.Visible = .T.
            .CurrentControl = "Check1"
            .Sparse = .F.
            .Header1.Caption = ""
            .Alignment = 2
            .Width = 20
            .Movable = .F.
        ENDWITH
    ENDPROC
    PROCEDURE Grid1.MouseDown(nButton, nShift, nXCoord, nYCoord)
        LOCAL lnWhere, lnRelRow, lnRelCol
        This.GridHitTest(m.nXCoord, m.nYCoord, @lnWhere, @lnRelRow, @lnRelCol)
        This.IsCheckBoxClicked = m.lnWhere == 3 And m.lnRelCol == 1
    ENDPROC
    PROCEDURE Grid1.Click
        IF This.IsCheckBoxClicked
            REPLACE col1 WITH !col1 IN This.RecordSource
        ENDIF
    ENDPROC
ENDDEFINE

© www.soinside.com 2019 - 2024. All rights reserved.