People who have used VB know that can increase the sharing method in the project, and how to store their own classes like VB in Delphi? Through the following explanation, I think you will have something to gain. First, add a library unit in the process of clicking on the order of the menu for File -> New -> Unit This will add a library unit for your project. Newly added library units such as:
Unit global; // Name of the library unit
Interface file: // <--- Add to select the selective library unit list item information end.
Second, add your own class in the library unit in Object Pascal, declare class with keyword class. Use the following title:
TYPE CTESTCLASS = Class File: / / Define a class, naming rules I look at Delphi-related naming rules End;
Of course, this code, there is no practical use, just declares an empty class, and the class does not have any data and operations, below we can add data and methods to the class.
TYPE CTESTCLASS = Class Timentage: String; Procedure SetText (Text: String); Function GetText: String; End;
The class of function members and process members become a class. Their descriptions and definition methods are similar to those of ordinary functions and processes, and the only difference is to add clarity and period in front of the function name and process name. ProCDEURE CTESTCLASS.SETTEXT (TEXT: STRING); begin tMessage: = text;
Function CTESTCLASS.GETTEXT: STRING; Begin getText: = tMESSAGE; END;
Such a simple class is written, you can call as follows. To organize the above code, the complete code of this library unit is as follows:
Unit global; // Name of the library unit
Interface file: // Interface section Uses Windows; // Requires other library unit list TYPE FILE: // Interface Type Definition CTESTCLASS = Class Timentage: String; Procedure SetText (Text: String); function GetText: string; end;
IMPLEMENTATION
ProCDEURE CTESTCLASS.SETTEXT (TEXT: STRING); begin tMessage: = text;
Function CTESTCLASS.GETTEXT: STRING; Begin getText: = tMESSAGE; END;
End.
Third, call the method in the custom library unit file (or other library unit) in the file you need to reference, add your own library unit name
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Global; File: // Note that Global is the name of the library unit you write.
Once your library unit is referenced in the USES section, you can call as follows: var TCLASS: CTestClass; this can be called as the form class in the current file. The full code is as follows:
Unit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Global; Type TFORM1 = Class (TFORM) private {private declarations} public {public declarations}
Var Form1: TForm1; Tclass: CTestClass; file: // The reference declaration of the class you have to increase
IMPLEMENTATION
{$ R * .dfm}
Procedure TFORM1.FORMCREATE (Sender: Tobject); begin tclass.create; tclass.settext ('This is a class test'); showMessage (tclass.gettext); file: // This is the class written by you yourself A test end;
End.
Ok, after entering the code over your computer, run a try. Here is just a simple example of the reference unit, please refer to the details of the library unit and class programming in the relevant books.