关于Delphi编程的问题?很急!!!200分!!

来源:百度知道 编辑:UC知道 时间:2024/06/24 11:42:36
有一个FormA上有多个Text
在第一个TextA上回车打开FromB,在FormB的DBGrid上选择一行回车将值返回到TextA上
然后在 TextB上回车打开FromB,在FormB的DBGrid上选择一行回车将值返回TextB上
FormB返回不是固定的控件的Name,是变量
这样的怎么实现?
哪位大虾帮个忙啊???
jinglinggg@126.com
多谢啊

将FormA上的多个Text的OnKeyPress事件全部指向Edit1KeyPress:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses unit2;

{$R *.dfm}

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then //如果按下了回车键
begin
if Sender is TEdit then
begin
form2.EditTextObj := TEdit(Sender);
form2.Show;
end;
end;
end;

end.

end;

下面是FormB的一些关键代码:
type
TForm2 = class(TForm)
DBGrid1: TDBGrid;
private
{ Private decl