把你相關的代碼發出來看看。
授人以渔,不授人以鱼。
frm_Test = CREATEOBJECT("Form") WITH frm_Test .AddObject("Container1", "my_Container") WITH .Container1 .Arrange .A(5) && 在這裏修改輸入的參數測試 .Visible = .T. ENDWITH .AutoCenter = .T. .Show(1) ENDWITH RETURN DEFINE CLASS my_Container AS Container ROWcount = 10 Indexid = 1 ADD OBJECT Label1 AS Label WITH Caption = "", Top = 5, Left = 5, Height = 25, AutoSize = .T. PROCEDURE Arrange WITH This .Top = 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE A LPARAMETERS lnTree IF (PCOUNT() < 1) .OR. (VARTYPE(lnTree) != "N") lnTree = THIS.Indexid ELSE IF lnTree > THIS.ROWcount lnTree = THIS.Indexid ENDIF ENDIF This.Label1.Caption = "lnTree = " + STR(lnTree,3) ENDPROC ENDDEFINE
frm_Test = CREATEOBJECT("Form") WITH frm_Test .AddObject("Container1", "my_Container") WITH .Container1 .Arrange .B(5) .Visible = .T. ENDWITH .AutoCenter = .T. .Show(1) ENDWITH RETURN DEFINE CLASS my_Container AS Container ROWcount = 10 Indexid = 1 ADD OBJECT Label1 AS Label WITH Caption = "", Top = 5, Left = 5, Height = 25, AutoSize = .T. ADD OBJECT Label2 AS Label WITH Caption = "", Top = 35, Left = 5, Height = 25, AutoSize = .T. PROCEDURE Arrange WITH This .Top = 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE A LPARAMETERS lnTree IF (PCOUNT() < 1) .OR. (VARTYPE(lnTree) != "N") lnTree = THIS.Indexid ELSE IF lnTree > THIS.ROWcount lnTree = THIS.Indexid ENDIF ENDIF This.Label1.Caption = "lnTree = " + STR(lnTree,3) ENDPROC PROCEDURE B(lnTree) This.Label2.Caption = "這是額外的動作" IF VARTYPE(lnTree) == "N" This.A(lnTree) ENDIF ENDPROC ENDDEFINE
frm_Test = CREATEOBJECT("Form") WITH frm_Test .AddObject("Container1", "SubContainer") && 從派生類建立實例對象 WITH .Container1 .Arrange .A(5) && 調用對象的A方法,即派生類中的方法,它自己調用父類代碼 .Visible = .T. ENDWITH .AutoCenter = .T. .Show(1) ENDWITH RETURN * 父類定義 DEFINE CLASS my_Container AS Container ROWcount = 10 Indexid = 1 ADD OBJECT Label1 AS Label WITH Caption = "", Top = 5, Left = 5, Height = 25, AutoSize = .T. ADD OBJECT Label2 AS Label WITH Caption = "", Top = 35, Left = 5, Height = 25, AutoSize = .T. PROCEDURE Arrange WITH This .Top = 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE A LPARAMETERS lnTree IF (PCOUNT() < 1) .OR. (VARTYPE(lnTree) != "N") lnTree = THIS.Indexid ELSE IF lnTree > THIS.ROWcount lnTree = THIS.Indexid ENDIF ENDIF This.Label1.Caption = "lnTree = " + STR(lnTree,3) ENDPROC PROCEDURE B(lnTree) This.Label2.Caption = "父類中B方法執行的動作" IF VARTYPE(lnTree) == "N" This.A(lnTree) ENDIF ENDPROC ENDDEFINE * 派生類定義 DEFINE CLASS SubContainer AS my_Container PROCEDURE A(lnTree) This.Label2.Caption = "派生類中A方法執行的動作" my_Container::A(lnTree) && 直接指定父類中需求執行的事件或方法,不限於本身A方法的父代碼 *DODEFAULT(lnTree) && 只能執行本身A方法的父代碼 ENDPROC ENDDEFINE