Delphi入门系列(八)类之结构

一个类的文件名.pas

 1 unit Unit1;//单元名也就是文件名
 2 
 3 interface
 4 
 5 uses //引用单元,类似于C# using
 6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
 8 
 9 type
10   TForm1 = class(TForm) //定义了一个名为TForm1的类名,并继承子TForm,注意class后面的括号这里写的继承子哪个类或则接口,如果单独一个类可以不用括号,一个类只能也一个父类,能够继承多个接口
11   private //私有声明
12     { Private declarations } 
13   public //公共声明
14     { Public declarations }   //声明包含需要的函数、过程、属性等 如果父类有virtual dynamic 可以加override 重写 按住 ctrl+shift+c 能够自动生成方法体。
15   end;
16 
17 var
18   Form1: TForm1;//定义一个全局变量.
19 /*以上声明语句*/
20 implementation
21 /*以下执行语句*/
22 {$R *.dfm}
23 /*构建自己的方法体、函数、等*/
24 end.

如何进行类的实例化。

定义 type                                                                     C# 版

        Ttest=class                                                          public class Ttest

     end;                         {}

定义一个变量类型                     Ttest obj1=new Ttest(); 实例化的时候也会调用

    obj1:Ttest                       默认的构造函数。

    begin

      obj1:=Ttest.Create;   对于Create 的调用会自动激活一个默认的构造函数。

   end;

 

posted on 2016-10-26 21:11  Zlcn  阅读(200)  评论(0)    收藏  举报

导航