在 delphi 里面新建一个类,可以使用 type 关键字进行定义,以下是代码示例:
typeTNewClass=Class //继承自某类: Class(TObject)
Private
{私有声明}
Protected
{保护声明}
Public
Procedure MyProcedure()
{公有声明}
end
用class关键字比如你要建立一个学生类:
type
Tstudent = class
name : string[10]
sex: char[2]
procedure dosomething
function MyFun:int
private
num : integer
public
procedure dosomething2
end
建好了类一般要创建对象才能用,你这样创建
var
student : Tstudent
begin
student := Tstudent.Create
end
这样一个学生类的实例student就创建出来了,就可以用它的上面定义的属性跟方法了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)