unit Unit2; //类似于程序单元首部,由保留字Unit加单元名组成,同一个工程中单元名是唯一的
interface // (用于定义) Interface部分称为接口部分,用于声明引用的、常量、类型、变量、过程和函数
uses //单元引用部分 类似于c语言的include
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFFFF = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
{In an event handler, the Sender parameter indicates which component received the event
and therefore called the handler. Sometimes it is useful to have several components
share an event handler that behaves differently depending on which component calls it.
You can do this by using the Sender parameter. }
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FFFF: TFFFF;
implementation // (用于实现) Implementa-tion部分(实现部分)也可以声明引用的单元、常量、类型、变量、那么这两者有什么区别呢?
{$R *.dfm}
procedure TFFFF.Button1Click(Sender: TObject);
var
t: Integer;
begin
t := StrToInt(Edit1.Text); //变量赋值操作,常量赋值用=,变量赋值用:=
Label1.Caption := IntToStr(t mod 10); //对象.属性 := 表达式,将表达式的值赋值给对象属性
end;
procedure TFFFF.Button2Click(Sender: TObject);
var
t: Integer;
begin
t := StrToInt(Edit1.Text);
Label2.Caption := IntToStr((t mod 100) div 10);
end;
procedure TFFFF.Button3Click(Sender: TObject);
var
t: Integer;
begin
t := StrToInt(Edit1.Text);
Label3.Caption := IntToStr((t mod 1000) div 100);
end;
procedure TFFFF.FormClick(Sender: TObject);
begin
Edit1.Text := 'Hello' + 'Delphl' + 'li'; //delphi只有一个字符串运算符‘+’
end;
end.