6

2つのTEditコントロールを取得しました。edit1からタブで移動すると、edit2がフォーカスを受け取ります。Edit1のOnExitイベントには、次のコードがあります。

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  edit2.Enabled := false;
  edit2.Enabled := true;
  edit2.setfocus;
end;

Edit2に焦点が当てられています。ただし、そこには気配りはありません。入力を開始することはできますが、どのコントロールにフォーカスがあるかわからないため、混乱します。

一部のメッセージが適切に起動されない原因となっているEnabledプロパティの反転の原因にもっと興味がありますか?たとえば、edit2のOnEnterイベントはトリガーされていません。

それがまったく重要であるならば、これはD2006にあります。

返信いただきありがとうございます。

4

4 に答える 4

9

なぜ無効にして有効edit2にするのかわかりませんが、次のようにします。

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  edit2.Enabled := false;
  edit2.Enabled := true;
  edit2.setfocus;
  PostMessage(edit2.Handle, WM_SETFOCUS, 0, 0);
end;

ところで、私はアンドレアス・レイブランドに同意します。

于 2011-09-05T08:11:33.480 に答える
9

私はあなたが何か悪いことをしているのではないかと真剣に疑っています.最善の解決策はおそらく再設計です. フォーカスを受け取っている間、コントロールを無効にしてから有効にすることは想定されていません。

于 2011-09-05T08:21:13.753 に答える
0

There's a bunch of codes between disabling and enabling edit2.

Having a lot of code in the OnExit event handler of the previous active control does not require to disable the next active control. That code will execute before the next active control shows up the caret and will be able to receive user input. Just make sure that it does nót pass execution over by something like starting a new thread or using Application.ProcessMessages.

Set Screen.Cursor to crHourGlass to make it clear for the user that the next active control is not ready yet.

于 2011-09-05T21:35:10.760 に答える