理解 Delphi 的类(十一) - 深入类中的方法[3] - 方法在实现时的参数省略 -...

来源:百度文库 编辑:神马文学网 时间:2024/04/30 10:15:04

理解 Delphi 的类(十一) - 深入类中的方法[3] - 方法在实现时的参数省略

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)end;TBass = classfunction Fun1(x,y: Integer): Integer; virtual; {Fun1 有 virtual 指示字}function Fun2(x,y,z: Integer): Integer;        {Fun2 有三个参数、一个返回值}end;varForm1: TForm1;implementation{$R *.dfm}{ TBass }function TBass.Fun1(x, y: Integer): Integer; {方法实现时, 不能带 virtual 等指示字}beginResult := x + y;end;function TBass.Fun2(x,y,z: Integer): Integer; {方法实现时可以只有函数名; 如果带参数和返回值, 必须和定义时一样}beginResult := x + y + z;end;end.