代码:(按钮快捷键的设置方法为在字母前加&,如&R,&G,&B) unit test;
interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type
TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit;
btnRed: TButton; btnGreen: TButton; btnBlue: TButton;
procedure btnRedClick(Sender: TObject); procedure btnGreenClick(Sender: TObject); procedure btnBlueClick(Sender: TObject);
private
{ Private declarations } public
{ Public declarations }
end; var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnRedClick(Sender: TObject); begin
form1.Edit1.Font.Color := clred; end;
procedure TForm1.btnGreenClick(Sender: TObject); begin
form1.Edit1.Font.Color := clgreen; end;
procedure TForm1.btnBlueClick(Sender: TObject); begin
form1.Edit1.Font.Color := clblue; end; End.
第三章
3.8 下列实数中哪些是合法的,哪些是不合法的?不合法的请说明理由。 (A)0.25E+02 (B).25+2 (C)25E+2 (D)34.5 (E).123 (F)-3E-4 答:(A)合法,即为25
(B)不合法,小数点前必须有数字,如表示为0.25+2 (C)合法,即为2500 (D)合法,即为34.5 (E)不合法,同(2) (F)合法,即为-0.0003
。
3.12 数学式子sin30写成Delphi表达式是下列哪个?
。
(A)Sin30 (B)Sin(30) (C)SIN(30) (D)Sin(30*Pi/180) 答:D,使用正切函数时需要把角度转化为弧度表示。
第四章
4.7 利用3个数字编辑框分别输入小时、分、秒,换算共有多少秒,然后使用标签输出。 答:设计界面:
运行界面:
代码: unit Unit1;
interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Spin; type
TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel;
SpinEdit1: TSpinEdit; SpinEdit2: TSpinEdit; SpinEdit3: TSpinEdit; Label4: TLabel;
procedure SpinEdit1Change(Sender: TObject); procedure SpinEdit2Change(Sender: TObject); procedure SpinEdit3Change(Sender: TObject);
private
{ Private declarations }
procedure CalculateTimeToSencond(timeKind:String; time:integer); public
{ Public declarations } end; var
Form1: TForm1; hour: integer = 0; minute: integer = 0; second: integer = 0; tot:integer = 0; implementation
{$R *.dfm}
procedure TForm1.CalculateTimeToSencond(timeKind:String; time:integer); begin
if timeKind = 'hh' then hour := time
else if timeKind = 'mi' then minute := time
else if timeKind = 'ss' then second := time;
tot := hour * 60 * 60 + minute * 60 + second;
form1.Label4.Caption := '总共为' + IntToStr(tot) + '秒'; end;
procedure TForm1.SpinEdit1Change(Sender: TObject); begin
Form1.CalculateTimeToSencond('hh', StrToInt(Form1.SpinEdit1.Text)); end;
procedure TForm1.SpinEdit2Change(Sender: TObject); begin
Form1.CalculateTimeToSencond('mi', StrToInt(Form1.SpinEdit2.Text)); end;
procedure TForm1.SpinEdit3Change(Sender: TObject); begin
Form1.CalculateTimeToSencond('ss', StrToInt(Form1.SpinEdit3.Text)); end; end.