delphi中 按钮输入 多个编辑框的选择

2024-11-06 07:10:18
推荐回答(2个)
回答(1):

根据你的要求修改了一下,再银明试试:
=====unit1.pas文件:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
CurEdit:TEdit;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if TEdit(Form1.ActiveControl)=Edit1 then
CurEdit := Edit1
else if TEdit(Form1.ActiveControl)=Edit2 then
CurEdit := Edit2
else if TEdit(Form1.ActiveControl)=Edit3 then
CurEdit := Edit3;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if CurEdit<>nil then begin
CurEdit.Text := '12';
CurEdit.SetFocus; // 加上这个看袭搏乱怎么样!
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
CurEdit := nil;
end;

end.

=====unit1.dfm文件:

object Form1: TForm1
Left = 293
Top = 266
Width = 251
Height = 141
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 16
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Edit2: TEdit
Left = 16
Top = 40
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit2'拍档
end
object Edit3: TEdit
Left = 16
Top = 72
Width = 121
Height = 21
TabOrder = 2
Text = 'Edit3'
end
object Button1: TButton
Left = 152
Top = 56
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 3
OnClick = Button1Click
end
object Timer1: TTimer
Interval = 100
OnTimer = Timer1Timer
Left = 160
Top = 8
end
end

回答(2):

你直接赋值不行吗?