procedure Tw_f_zy_add.RG_xbEnter(Sender: TObject); begin if (key=13) then edit2.SetFocus; end; 编译不了,[Error] w_u_zy_add.pas(236): Undeclared identifier: 'key'
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Edit1: TEdit; RadioGroup1: TRadioGroup; Edit2: TEdit; procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private procedure OnKeyD(Sender: TObject; var Key: Word; Shift: TShiftState); { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key=VK_RETURN then begin RadioGroup1.Buttons[RadioGroup1.ItemIndex].SetFocus; RadioGroup1.Buttons[RadioGroup1.ItemIndex].OnKeyDown:= Onkeyd; end; end;procedure TForm1.OnKeyD(Sender: TObject; var Key: Word; Shift: TShiftState); begin edit2.SetFocus; end;end.
呵呵,我写的那个程序是临时性,你要真的用的话应该这样 在Form的ONCreate事件中 for i:= 0 to Radiogroup1.Items.Count-1 do RadioGroup1.Buttons[i].OnKeyDown:= Onkeyd;也就是事先将Group中的每个Button的OnKeyDown事件都赋值为Onkeyd,然后去掉Edit1KeyDown中的下面这句 RadioGroup1.Buttons[RadioGroup1.ItemIndex].OnKeyDown:= Onkeyd;
procedure Tw_f_zy_add.RG_xbEnter(Sender: TObject); begin if (key=13) then edit2.SetFocus; end;
事件OnEnter里写就可以
begin
if (key=13) then
edit2.SetFocus;
end;
编译不了,[Error] w_u_zy_add.pas(236): Undeclared identifier: 'key'
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
RadioGroup1: TRadioGroup;
Edit2: TEdit;
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
procedure OnKeyD(Sender: TObject; var Key: Word; Shift: TShiftState);
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_RETURN then
begin
RadioGroup1.Buttons[RadioGroup1.ItemIndex].SetFocus;
RadioGroup1.Buttons[RadioGroup1.ItemIndex].OnKeyDown:= Onkeyd;
end;
end;procedure TForm1.OnKeyD(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
edit2.SetFocus;
end;end.
在Form的ONCreate事件中
for i:= 0 to Radiogroup1.Items.Count-1 do
RadioGroup1.Buttons[i].OnKeyDown:= Onkeyd;也就是事先将Group中的每个Button的OnKeyDown事件都赋值为Onkeyd,然后去掉Edit1KeyDown中的下面这句
RadioGroup1.Buttons[RadioGroup1.ItemIndex].OnKeyDown:= Onkeyd;
begin
if (key=13) then
edit2.SetFocus;
end;