1.单元文件 p11
(1)单元头 unit xxx
(2)接口部分:从interface开始,到implementation之前结束。有uses、type、var等语句。
(3)实现部分:以implementation开始。
(4)初始化部分:以initialization开始。
(5)结束部分:以finalization开始。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
end;
end.
2.程序文件
(1)程序首部:program xxx;
(2)说明部分:有uses、type、var等语句。
(3)执行部分:begin开始,end结束。
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
3.注释方式 p15
(1)单行注释: //
(2)多行注释:{ } 或者(* *)
4. 常用标准函数
sqr(x) 平方
sqrt(y) 开根号
int(x) 取整
ord('A') 求ascii码
inc(x) inc(x,3) 自增
dec(x) 自减
odd(x) 奇函数
pred(x) x-1
succ(x) x+1
chr(x) 返回ascii值
5.静态数组
var
d:array [1..10] of integer; //一维数组
e:array [1..3,1..5] of integer; //二维数组
动态分配数组
var
c:array of integer;
begin
setlength(c,10);
writeln(c[0]);
readln;
end.
if a=b then
writeln(1)
else if a>b then
writeln(2)
else writeln(3);
7. for语句
a:=0;
for i:= 1 to 10 do
begin
inc(a);
writeln(a);
end;
readln;
8. while语句
i:=0;
while i<10 do
begin
writeln(i);
inc(i);
end;
9. 过程 procedure
procedure p1(a:integer);
begin
writeln(a);
end;
10.函数 function。 比procedure多一个返回值
function myinc(a:integer):integer;
begin
result:=a+1;
end;
11.调用参数传递方式
(1)值参数(形式参数):procedure f(a:integer);
(2)变量参数(传地址):procedure f(var a:integer);
(3)常参数: procedure f(const a:integer);
12. 定义记录 record。记录不能定义过程和函数,只是类型的集合。