请帮忙!!(30)

  • 主题发起人 主题发起人 bearyan
  • 开始时间 开始时间
B

bearyan

Unregistered / Unconfirmed
GUEST, unregistred user!
有以下程序,三个按键共用同一个程序段procedure TForm1.Button1Click(Sender: TObject);
begin
IF (Sender AS TButton).Caption = 'Button1' then
ShowMessage('Button1') else
IF (Sender AS TButton).Caption = 'Button2' then
ShowMessage('Button2') else
IF (Sender AS TButton).Caption = 'Button3' then
ShowMessage('Button3');
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
IF Edit1.Text = '1' then
Button1Click(Button1);
end;
现在我想输入1,就等于Button1按下(已经实现);但是输入2或3,想实现Button2或Button3按下该如何??
 
procedure TForm1.Edit1Change(Sender: TObject);
begin
IF Edit1.Text = '1' then
Button1Click(Button1) else
IF Edit1.Text = '2' then
Button1Click(Button2) else
IF Edit1.Text = '3' then
Button1Click(Button3);
end;
 
用ASCII值判断1 ASCII 492 ASCII 503 ASCII 51
 
procedure TForm1.Edit1Change(Sender: TObject);var str_name:string;
begin
str_name:='Button'+edit1.text;
Button1Click((self.FindComponent(str_name) as TButton));
end;
 
procedure TForm1.Edit1KeyPress(Sender: TObject;
var Key: Char);
begin
if Key in ['1'..'3'] then
Button1Click((self.FindComponent(Key) as TButton));
end;
 

Similar threads

S
回复
0
查看
663
SUNSTONE的Delphi笔记
S
S
回复
0
查看
686
SUNSTONE的Delphi笔记
S
S
回复
0
查看
906
SUNSTONE的Delphi笔记
S
S
回复
0
查看
884
SUNSTONE的Delphi笔记
S
S
回复
0
查看
795
SUNSTONE的Delphi笔记
S
后退
顶部