Use a pure object-oriented method in Delphi Select BLOG from Dabao45

xiaoxiao2021-03-06  46

Delphi uses pure object-oriented method Delphi's VCL technology to get a lot of programmers to get started very quickly: The programmer is only simple to drag and add a small number of PASCAL statements, huh, one can run very well Delphi program! Congratulations, you can have developed this great cause. However, when you have learned it for a while, I will not think so. Because Delphi is supported object-oriented language, all VCL Components are based on object-oriented language, then we use these object-oriented stuff to design some other things that are not how to be alive. Feeling, of course, here does not discuss the good or bad use without the object-oriented method, do not want to cause the protest of relevant people, after all, "radish greens". In Delphi, all controls are declared under the keyword of the Publish, which is also the default location of the component programming. In this way, if a Form2 wants to lead a control in Form1 (if it is unit1), as long as the use unit1 is OK, if Form1 is to reference the Form2's stuff, it can be made as foam. However, if I accidentally change the control in FORM2, isn't the code in the Form1 to rewrite the code? So, I advocate these controls as a dedicated element of the Form class, and the external form can access the controls through the properties published by the FORM class. For example: tform1 = class (tform) privte button1: tbutton end; however, this design is to solve the height package of members, but the compile will have an error. The TButton class can not find because we put the Button1 in private, Delphi It doesn't automatically register the TButton class. In fact, this problem is also simple. Just join the registerclasses ([TButton]) in Initialization, Of course, if there are different classes, the controls can be placed in the parameters of the registerclasses, because Its parameters are an array of controls. Of course, such an object-oriented design method is complicated than the previous "drag" method, but we have got a high degree of encapsulation, I think it is worth, what?

Author Blog:

Http://blog.9cbs.net/dabao45/

转载请注明原文地址:https://www.9cbs.com/read-79214.html

New Post(0)