理解 Delphi 的类(十) - 深入方法[19] - 过程中的方法
摘要://Delphi 支持过程中的方法 procedure TForm1.Button1Click(Sender: TObject); procedure alert(s: string); begin ShowMessage(s); end; begin alert('万一'); {万一} end;
阅读全文
posted @
2008-01-14 21:42
万一
阅读(3868)
推荐(0)
理解 Delphi 的类(十) - 深入方法[18] - 在接口区声明的方法都相当于提前声明了
摘要://要点18: 如果函数在接口区定义了, 就无需用 forward 提前声明了 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ...
阅读全文
posted @
2008-01-14 21:41
万一
阅读(4065)
推荐(0)
理解 Delphi 的类(十) - 深入方法[17] - 提前声明
摘要://要点17: 如果前面的方法要调用后面的方法, 后面的方法需要提前声明 function MyFunB(x: Integer): Integer; forward; {使用 forward 指示字提前声明} function MyFunA(x: Integer): Integer; begin Result := MyFunB(x) * 3; {要调用后面的方法, 后面的方法需要提前声明...
阅读全文
posted @
2008-01-14 21:40
万一
阅读(4070)
推荐(0)
理解 Delphi 的类(十) - 深入方法[16] - 方法的顺序
摘要://要点16: 在实现区(implementation), 自定义的方法是有顺序的 function MyFunA(x: Integer): Integer; begin Result := Sqr(x); {取平方} //MyFunB(x); {前面的函数不能调用后面的函数} end; function MyFunB(x: Integer): Integer; begin ...
阅读全文
posted @
2008-01-14 21:36
万一
阅读(4144)
推荐(0)
理解 Delphi 的类(十) - 深入方法[15] - 调用其他单元的函数
摘要://要点15: 调用其他单元的函数 //包含函数的单元: unit Unit2; interface function MyFun(x,y: Integer): Integer; {函数必须在接口区声明} implementation function MyFun(x,y: Integer): Integer; {函数必须在函数区实现} begin Result := x + y; ...
阅读全文
posted @
2008-01-14 21:34
万一
阅读(6858)
推荐(0)
理解 Delphi 的类(十) - 深入方法[14] - 在TForm1 类内声明的方法
摘要://要点14: 如果声明在 TForm1 类内, 那它就是 TForm1 类的一个方法了 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TFor...
阅读全文
posted @
2008-01-14 21:33
万一
阅读(4805)
推荐(1)
理解 Delphi 的类(十) - 深入方法[13] - 在 interface 区声明的方法
摘要://要点13: 需要给其他单元调用, 必须在 interface 声明, 但必须在 uses 区后面 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = clas...
阅读全文
posted @
2008-01-14 21:32
万一
阅读(4495)
推荐(0)
理解 Delphi 的类(十) - 深入方法[12] - implementation 区中的方法
摘要://要点12: implementation 区中的过程或函数, 只能在本单元调用 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ...
阅读全文
posted @
2008-01-14 21:31
万一
阅读(5165)
推荐(0)
理解 Delphi 的类(十) - 深入方法[11] - 参数前缀
摘要://要点11: 参数可以分为: 默认参数(传值)、var(传址)、out(输出)、const(常数)四类 {默认参数是传值, 不会被改变} function MyF1(x: Integer): Integer; begin Inc(x); Result := x; end; {var参数是传址, 会被改变} function MyF2(var x: Integer): Integer...
阅读全文
posted @
2008-01-14 21:29
万一
阅读(5099)
推荐(1)
理解 Delphi 的类(十) - 深入方法[10] - 默认参数
摘要://要点10: 过程和函数都可以有一个或多个默认参数; 但必须在非默认参数后面 function MyFun(s1: string; s2: string='好人'): string; begin Result := s1 + s2; end; {调用} procedure TForm1.Button1Click(Sender: TObject); var str1,str2: str...
阅读全文
posted @
2008-01-14 21:28
万一
阅读(4646)
推荐(0)
理解 Delphi 的类(十) - 深入方法[9] - 调用时的括号
摘要://要点9: 没有参数的过程或函数, 在调用时可以省略 (); 也可以带着 function MyFun: string; begin Result := 'ok'; end; {调用} procedure TForm1.Button1Click(Sender: TObject); var s: string; begin s := MyFun; ShowMessage(s);...
阅读全文
posted @
2008-01-14 21:27
万一
阅读(4084)
推荐(0)
理解 Delphi 的类(十) - 深入方法[8] - 如果忘了返回值
摘要://要点8: 忘了写返回值的函数, 也可以当过程用(没有人会这样做, 但 Delphi 竟然也允许) function MyFun(var x: Integer): string; begin x := x + 1; end; {调用} procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin i :...
阅读全文
posted @
2008-01-14 21:26
万一
阅读(4126)
推荐(0)
理解 Delphi 的类(十) - 深入方法[7] - Result
摘要://要点7: 不仅如此, Result 还有更灵活的运用 function MyFun(b: Byte): Char; begin //Result := Char(b); {我们当然可以这样写} Byte(Result) := b; {这样也行} end; {System 中就有这样一个函数} function TObject.ClassType: TClass; begin ...
阅读全文
posted @
2008-01-14 21:23
万一
阅读(4657)
推荐(0)
理解 Delphi 的类(十) - 深入方法[6] - Result
摘要://要点6: Result 可以参与运算, "函数名"不可以 function MyFun(x,y: Integer): Integer; begin Result := x + y; Result := Result * 2; end;
阅读全文
posted @
2008-01-14 21:21
万一
阅读(3967)
推荐(0)
理解 Delphi 的类(十) - 深入方法[5] - Result 与函数名
摘要://要点5: 函数的返回值可以使用 Result , 也可以使用函数名(但不提倡) function MyFun1(x,y: Integer): Integer; begin Result := x + y; end; function MyFun2(x,y: Integer): Integer; begin MyFun2 := x + y; end;
阅读全文
posted @
2008-01-14 21:19
万一
阅读(4476)
推荐(0)
理解 Delphi 的类(十) - 深入方法[4] - 共同类型的参数的简化写法
摘要://要点4: 多个相同类型的参数可以简化写法 function MyFun(str: string; x,y,z: Integer): string; begin Result := str + IntToStr(x + y + z); end;
阅读全文
posted @
2008-01-14 21:18
万一
阅读(4084)
推荐(0)
理解 Delphi 的类(十) - 深入方法[3] - 调用时参数分割
摘要://要点3: 在调用时, 参数使用 , 分割的 function MyFun(x: Integer; y: Integer): Integer; begin Result := x + y; end; {调用} procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin i := MyFun(1,2);...
阅读全文
posted @
2008-01-14 21:15
万一
阅读(3762)
推荐(0)
理解 Delphi 的类(十) - 深入方法[2] - 参数分割
摘要://要点2: 过程和函数都可以有一个或多个参数; 参数用 ; 号分割 procedure MyProc(i: Integer); begin ShowMessage(IntToStr(i)); end; function MyFun(x: Integer; y: Integer): Integer; begin Result := x + y; end;
阅读全文
posted @
2008-01-14 21:14
万一
阅读(3890)
推荐(1)
理解 Delphi 的类(十) - 深入方法[1] - 定义
摘要:类中包含字段、方法和属性(属性包含事件); 字段是靠方法组织与操作的; 属性也只是方便和规范了字段与方法的使用. 因此我觉得: 方法是最重要的. 方法无处不在, 它不仅仅存在与类中. 先从非类中的方法谈起吧, 因为类中的方法也拥有全部这些特性. 离开类的怀抱, 我们更喜欢把方法叫做过程或函数. //要点1: 过程用 procedure 定义, 函数用 function 定义; 过程没有返回值...
阅读全文
posted @
2008-01-14 15:01
万一
阅读(4332)
推荐(1)
理解 Delphi 的类(九) - 关于类的向前声明
摘要://例1: 这是正确的 TClassA = class Field1: string; Field2: Integer; end; TClassB = class Field1: string; Field2: Integer; Field3: TClassA; {字段 Field3 的类型是刚刚新定义的 TClassA 类型} end;...
阅读全文
posted @
2008-01-14 13:33
万一
阅读(5861)
推荐(1)