mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
- unit mainunit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- IntegerProc = procedure (Var Number: Integer);
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- GroupBox1: TGroupBox;
- RadioButton1: TRadioButton;
- RadioButton2: TRadioButton;
- Edit1: TEdit;
- Label1: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- OneIntProcInstance: IntegerProc;
- Number: Integer;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TripleTheValueProc (Var Value: Integer);
- begin
- Value := Value * 3;
- ShowMessage ('The initail Value is tripled! Now it is:' + IntToStr (Value)+'.');
- end;
- procedure DoubleTheValuePorc (Var Value: Integer);
- begin
- Value := Value * 2;
- ShowMessage ('The initail Value is doubled! Now it is:' + IntToStr (Value)+'.');
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Number:=0;
- RadioButton1.Checked:=True;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if (Edit1.Text='') then
- begin
- Showmessage('请先在编辑框中输入初始数值,然后选择操作类型后再点击这个按钮!');
- Edit1.SetFocus;
- end
- else
- begin
- if (RadioButton1.Checked) then
- begin
- Number:=StrToInt(Edit1.Text);
- OneIntProcInstance:=DoubleTheValuePorc;
- OneIntProcInstance(Number);
- end
- else
- begin
- Number:=StrToInt(Edit1.Text);
- OneIntProcInstance:=TripleTheValueProc;
- OneIntProcInstance(Number);
- end;
- end;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- Close;
- end;
- end.