摘要: //要点16: 在实现区(implementation), 自定义的方法是有顺序的 function MyFunA(x: Integer): Integer; begin Result := Sqr(x); {取平方} //MyFunB(x); {前面的函数不能调用后面的函数} end; funct 阅读全文
posted @ 2020-04-20 17:18 范思哲 阅读(135) 评论(0) 推荐(0)
摘要: //要点15: 调用其他单元的函数 //包含函数的单元: unit Unit2; interface function MyFun(x,y: Integer): Integer; {函数必须在接口区声明} implementation function MyFun(x,y: Integer): In 阅读全文
posted @ 2020-04-20 17:08 范思哲 阅读(141) 评论(0) 推荐(0)
摘要: //要点14: 如果声明在 TForm1 类内, 那它就是 TForm1 类的一个方法了 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dia 阅读全文
posted @ 2020-04-20 17:06 范思哲 阅读(248) 评论(0) 推荐(0)
摘要: //要点13: 需要给其他单元调用, 必须在 interface 声明, 但必须在 uses 区后面 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form 阅读全文
posted @ 2020-04-20 16:57 范思哲 阅读(415) 评论(0) 推荐(0)
摘要: //要点12: implementation 区中的过程或函数, 只能在本单元调用 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialog 阅读全文
posted @ 2020-04-20 16:53 范思哲 阅读(209) 评论(0) 推荐(0)
摘要: //要点11: 参数可以分为: 默认参数(传值)、var(传址)、out(输出)、const(常数)四类 {默认参数是传值, 不会被改变} function MyF1(x: Integer): Integer; begin Inc(x); Result := x; end; {var参数是传址, 会 阅读全文
posted @ 2020-04-20 16:51 范思哲 阅读(202) 评论(0) 推荐(0)
摘要: //要点10: 过程和函数都可以有一个或多个默认参数; 但必须在非默认参数后面 function MyFun(s1: string; s2: string='好人'): string; begin Result := s1 + s2; end; {调用} procedure TForm1.Butto 阅读全文
posted @ 2020-04-20 16:48 范思哲 阅读(125) 评论(0) 推荐(0)
摘要: //要点9: 没有参数的过程或函数, 在调用时可以省略 (); 也可以带着 function MyFun: string; begin Result := 'ok'; end; {调用} procedure TForm1.Button1Click(Sender: TObject); var s: s 阅读全文
posted @ 2020-04-20 16:46 范思哲 阅读(200) 评论(0) 推荐(0)
摘要: //要点8: 忘了写返回值的函数, 也可以当过程用(没有人会这样做, 但 Delphi 竟然也允许) function MyFun(var x: Integer): string; begin x := x + 1; end; {调用} procedure TForm1.Button1Click(S 阅读全文
posted @ 2020-04-19 18:48 范思哲 阅读(174) 评论(0) 推荐(0)
摘要: //要点7: 不仅如此, Result 还有更灵活的运用 function MyFun(b: Byte): Char; begin //Result := Char(b); {我们当然可以这样写} Byte(Result) := b; {这样也行} end; {System 中就有这样一个函数} f 阅读全文
posted @ 2020-04-19 18:40 范思哲 阅读(177) 评论(0) 推荐(0)