How to write your own visual control with Delphi -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- Visual Component is actually a class (Class), to write a class, you can Written in the * .pas file. But to write a control, you must use a package (package). Select New from the File menu, create a new package, which is the package that stores and installs the control. Then click the Add button in the Package window to add an element (Unit). Select New Component at the top of the dialog that pops up. Because all attributes, methods, events, events cannot be compiled by themselves, so you need to select ancestors (or "parent class" or "base class"), then add your own properties, methods, events. . Select the ancestor class in the drop-down box after Anadem Type. Since the written visual control must be drawn, TGRAPHICCONTROL is selected as ancestral class. Then enter the name of the new control (class) in the Class name box, generally starting with "T". Palette Page is used to select a control page name in the window of the new control in the window of Delphi, such as "Standard", this can be takeny. Add the path and file name of the new control file in Unit File Name, click the OK button. The new control is added. You can now write code for the control. The following is to write a scroll bar that can customize the picture as an example, and the method of writing visual controls is described. According to the above method, select TGRAPHICCONTROL for ancestral class, the name of the new control is TPIGHORIZONTALSCROLLER. After selecting the file path and the file name, click the OK button to start writing the code. Each control will be created and deleted, so these two processes must be prepared first. For each process in the control, you must first define before, and then write it later. There are three processes or attributes: 1. Definition in private is used inside the control, people who use this control cannot be seen; Second, the definition defined after protected is generally not seen, only in others The control is visible as a ancestors to write other controls as ancestors; III. Only those defined after publicness allows others to call in the program; four, can be seen in the property window (Object Inspector) after PublisHed. Since the creation and deletion process is automatically executed when the control is created during the programming process, it is also possible to be called when the control is created during the program run, so it defines it after public (1). (This sequence number indicates the position of the code in the attached source program, and the same below) may now not know what should be written in these two processes, how to dear. We will talk below. We first add some properties to this control. We define a max attribute to set or read the maximum value of the scroll bar. Because the properties are generally not directly used in the program, there is a variable to define a variable, and the attribute corresponds to, or the value is modified or read. Because it is only used inside the control, we define it after private (2). (Generally, the variables associated with the attribute are defined after "F", such as fmax), and then define the attribute. This attribute needs to be seen in the Object Inspector window, so define it again.
The definition syntax is: Property