Delphi语言学习7-类和对象

1.类的声明格式

type   className = class [abstract | sealed] (ancestorClass)      memberList   end;

2.类的声明和使用

//定义 type TMemoryStream = class(TCustomMemoryStream)            private              FCapacity: Longint;              procedure SetCapacity(NewCapacity: Longint);            protected              function Realloc(var NewCapacity: Longint): Pointer; virtual;              property Capacity: Longint read FCapacity write SetCapacity;            public              destructor Destroy; override;              procedure Clear;              procedure LoadFromStream(Stream: TStream);              procedure LoadFromFile(const FileName: string);              procedure SetSize(NewSize: Longint); override;              function Write(const Buffer; Count: Longint): Longint; override;          end;//使用 var stream: TMemoryStream;     stream := TMemoryStream.Create;

3.类的继承

//继承一个类type TSomeControl = class(TControl);//根类 TObjecttype TMyClass = class     ...     end;//等价于type TMyClass = class(TObject)     ...     end;

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索class
, override
, type
, end
procedure
,以便于您获取更多的相关知识。

时间: 2024-09-13 16:36:46

Delphi语言学习7-类和对象的相关文章

Javascript学习6 - 类、对象、继承

原文:Javascript学习6 - 类.对象.继承     Javasciprt并不像C++一样支持真正的类,也不是用class关键字来定义类.Javascript定义类也是使用function关键字来完成的.     在Javascript中,可以把对象(object)定义为"属性的无序集合",每个属性存放一个原始值.对象或者函数.理解这一点非常重要. ECMAScript定义:对象由特性(attribute)构成,特性可以是原始值,可以是引用值,如果特性存放的是函数,它将被看作对

C++语言基础 例程 类和对象的简单应用举例

贺老师的教学链接  本课讲解 实例1:求出三角形的周长和面积 #include<iostream> #include<Cmath> #include<cstdlib> using namespace std; class Triangle { public: void setABC(double x, double y, double z);//置三边的值,注意要能成三角形 double perimeter();//计算三角形的周长 double area();//计算

Delphi语言学习8-类成员(字段和方法)

1.Class Fields //例1 成员变量type TAncestor = class Value: Integer; end; TDescendant = class(TAncestor) Value: string; // hides the inherited Value field end;var MyObject: TAncestor;begin MyObject := TDescendant.Create; MyObject.Value := 'Hello!' // error

Delphi语言学习5-函数和方法

1.函数的定义 //格式function functionName(parameterList): returnType; directives; localDeclarations;begin statementsend;//例1function WF: Integer;begin WF := 17;end;//例2function WF: Integer;begin Result := 17;end;//例3 function MyFunction: Integer;begin MyFunc

Delphi语言学习4—数据类型的基本使用

1.基本数据类型 1)Delphi自带了一些对基本类型的操作函数,如Ord ,Pred,Succ ,High,Low 2)枚举类型 声明 type Suit = (Club, Diamond, Heart, Spade);//where Ord(Club) returns 0, Ord(Diamond) returns 1... 如果枚举类型的名称和类型名重复的使用方法: type TSound = (Click, Clack, Clock)procedure TForm1.DBGridEnte

Delphi语言学习3-数据类型概述

Delphi有如下数据类型: 1.简单数据类型: ordinal integer character Boolean enumerated subrange real 2.字符串类型 string 3.集合类型 set array record file class class reference interface 4.指针类型 pointer 5.函数类型 procedural 6.变量类型 Variant 7.类型声明 type identifier

Delphi语言学习9-函数的静态和动态加载

1.静态加载 procedure DoSomething; external 'MYLIB.DLL'; 2.动态加载 uses Windows, ;type TTimeRec = record Second: Integer; Minute: Integer; Hour: Integer; end; TGetTime = procedure(var Time: TTimeRec); THandle = Integer; var Time: TTimeRec; Handle: THandle; G

Delphi语言学习6-函数参数

1.参数定义方式 function Power(X: Real; Y: Integer): Real; //(X, Y: Real) //(var S: string; X: Integer) //(HWnd: Integer; Text, Caption: PChar; Flags: Integer) //(const P; I: Integer) 2.引用类型和值类型 //DoubleByRef 的参数值会改变function DoubleByValue(X: Integer): Integ

Delphi语言学习2-基本语法

1.基本赋值语句 Size :=20; Price :=10; 2.特殊符号 1)单个特殊符号 # $ & ' ( ) * + , - . / : ; < = > @ [ ] ^ { } 2)成对的特殊符号 (* (. *) .) .. // := <= >= <> 3).等价的特殊符号 特殊符号 等价的特殊符号 [ (. ] .) { (* } *) 3.注释和编译器指令 1)注释 { Text between a left brace and a right