Delphi unit files
1. library unit header: wherein declares the name of the library unit.
2.Interface part:
starting from the reserved word interface, ends Implementation reserved word, which is used means, constants, data types, variables, procedures and functions declared reference in the variable declaration part of Interface, constants, data types, procedures, functions can be used for external references, for the whole procedure is common. that is, for all of the unit cell reference, these statements are visible and accessible.
in the Interface part, simply write the header procedures and functions, particularly in the following definition is given in the implementation section.
Interface portion divided into a plurality of selectable portions, each portion of units introduced ( uses), constant Description section, part of the type described, the variable portion described, the process and function declarations portion.
3.Implementation portion:
Implementation part is partially divided into two parts declaration section, including a reference unit, constants, types, variables, and processes. function declaration, and this is similar to the Interface part.
distinction is twofold:
(1): in this unit is only part of the declaration of the public Implementation visible, other single Even if the reference cell, can not access them.
(2): In the procedures and functions declared Implementation section, need not follow the rules defined in the statement after the first, and can be directly written procedures and functions defined in another part of the Interface. define procedures and functions declared in part.
. 4.. Dfm} {$ R & lt *
{If a corresponding file is a unit of the form, will phrase. $ R & lt external instruction used to load a resource file, herein means loaded with the same name of the form file is compiled.}
5. initialization section:
for initializing the cell library, the first execution code here if a plurality of cells comprising the library initialization portion thereof so on and the order of execution of the Program uses a reference part in order of appearance is consistent units..
6.Finalization part:
typically part of the resource allocation if a plurality Initialization for releasing the library unit contains Finalization portion, and the execution order Initialization portion opposite.
. 1 Unit MainFrm; {library unit header} 2 . 3 interface {interface section} . 4 . 5 uses . 6 the Windows, Forms, StdCtrls; . 7 . 8 type . 9 TForm1 = class (a TForm) 10 Procedure the FormCreate (Sender: TObject); . 11 Private 12 is { Declarations} Private 13 is public 14 Procedure MyButtonClick (SENDER: TObject); 15 {} public Declarations 16 End; . 17 18 is var . 19 the Form1: TForm1; 20 is 21 is implementation {achieve some} 22 is 23 is uses zidingyi 24 25 {$ R & lt * . Dfm} 26 is 27 Procedure TForm1.FormCreate (Sender: TObject); 28 var 29 the MyButton: the TButton; 30 the begin 31 is the MyButton: = TButton.Create (Self); 32 MyButton.Parent: = Self; 33 is // tell the creation method to Form1 MyButton display 34 is MyButton.Caption: = 'a test'; 35 MyButton.OnClick: = MyButtonClick; 36 MyButton.Show; 37 [ End; 38 is 39 TForm1.MyButtonClick Procedure (SENDER: TObject); 40 the begin 41 is Application.MessageBox (PAnsiChar (the TButton (SENDER) .Caption), ' the Test the Component ' ); 42 is the TButton (SENDER) .Caption: = ' test two ' ; 43 is End; 44 is 45 initialization alternative initialization section {} 46 is ........ 47 finalization end portion {} 48 ......... 49 50 end. {} end terminator