Preface
The role of virtual functions is explained in professional terms by implementing polymorphism. polymorphism separates interfaces from implementations. interpreting with image languages means implementing a common approach, however, different strategies are adopted due to individual differences. Another key to polymorphism is that all objects are operated by pointers or references to the base class. In C ++ and Java, the use of virtual functions is handy. abstract classes only declare and do not implement them. The specific implementation is in the subclass,
You can call the subclass method by assigning a subclass instance to the parent object. But how can we implement it in Pb?
1. Create the parent object u_main and create virtual functions (not implemented) and instance variables.
Global Type u_main from userobject
End type
Boolean ib_zdjs = false
// Assign a value when the user needs to modify the number of years at the beginning of the year
Boolean ib_ncs = false
// Whether the data window has been modified
Boolean ib_modify = false
// Document serial number of the current report
String is_wsxh
End Variables
Forward prototypes
Public Function Integer uf_save ()
Public subroutine uf_preview (integer ai_fs)
Public subroutine uf_init ()
Public subroutine uf_setxgncs (integer ai_ I)
Public subroutine uf_help ()
Public subroutine uf_add ()
Public subroutine uf_delete ()
Public subroutine uf_js ()
End prototypes
Public Function Integer uf_save (); Return 0
End Function
Public subroutine uf_preview (integer ai_fs); // AI = 0 is preview AI = 1 is print
End subroutine
Public subroutine uf_init (); // load data window
End subroutine
Public subroutine uf_setxgncs (integer ai_ I); // modify the number of beginning of year
End subroutine
Public subroutine uf_help ();
End subroutine
Public subroutine uf_add ();//
End subroutine
Public subroutine uf_delete ();//
End subroutine
Public subroutine uf_js ();//
End subroutine
Second, inherit the parent object u_main to generate multiple objects and implement the virtual functions of the parent object respectively.
Global u_dk003_lr u_dk003 _
Public Function Integer uf_save ()
Public subroutine uf_init ()
Public subroutine uf_preview (integer ai_fs)
Public subroutine uf_help ()
Public Function Integer uf_save (); dw_1.update ()
Return 1
End Function
Public subroutine uf_init (); long ll_row
Int I
Dw_1.settransobject (sqlca)
Ll_row = dw_1.retrieve ()
If ll_row = 0 then
Ll_row = dw_1.insertrow (0)
End if
End subroutine
Public subroutine uf_preview (integer ai_fs); If ai_fs = 0 then
Openwithparm (w_dw_print_ws, "d_dk003_print ")
End if
If ai_fs = 1 then // print
Dw_print.dataobject = "d_dk003_print"
Dw_print.settransobject (sqlca)
Dw_print.retrieve ()
End if
End subroutine
Public subroutine uf_help (); openwithparm (w_help, "dk003 ")
End subroutine
3. Use the u_main variable to create multiple instance variables for flexible programming
U_main uo_1
Uo_1 = create u_dk003_lr // create a sub-object instance
Uo_1.uf_init () // The method in u_dk003_lr is the sub-object.
Uo_1 = create u_dk004_lr // create a sub-object instance
Uo_1.uf_init () // The method in u_dk004_lr is the sub-object.