Recent

Author Topic: SetFocus does not work  (Read 11449 times)

epsilon

  • New Member
  • *
  • Posts: 21
SetFocus does not work
« on: February 17, 2005, 04:17:11 pm »
Hi there

Trying to set focus by
Code: [Select]
Edit1.SetFocus;  the following errormesage occurs:
Quote
1) Project project1 raised exception class 'EInvalidOperation'
An appliction.exe is created but if I run it, the message
Quote
[TCustomForm.SetFocus] Form1: TForm1 Can not focus

appears. Next, even if I set a TabOrder ordering,  the keystroke of "TAB" does nothing.

Any ideas, what's wrong?  Epsilon

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2680
SetFocus does not work
« Reply #1 on: February 18, 2005, 12:26:54 pm »
where and when do you can Edit1.setfocus?

You cannot focus an invisible component.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

epsilon

  • New Member
  • *
  • Posts: 21
SetFocus does not work
« Reply #2 on: February 18, 2005, 12:54:21 pm »
O.K. I have to write the code Edit1.setfocus as an OnPaint event of the Form1.
But, I still don't know how to realize the TAB ordering. It really does not work. :(

matthijs

  • Hero Member
  • *****
  • Posts: 537
SetFocus does not work
« Reply #3 on: February 19, 2005, 07:49:28 pm »
Use the 'ActiveControl' property to set the focus on Edit1 when the forms shows. Right click on the form and set the tab-order anyway you like. I just tried it and it works.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2680
SetFocus does not work
« Reply #4 on: February 21, 2005, 12:33:20 pm »
Quote from: "epsilon"
O.K. I have to write the code Edit1.setfocus as an OnPaint event of the Form1.


One of the worst places to place a setfocus is OnPaint. On paint will fire pretty often and thus calling unnesesary setfocus. Besides, changing focus might trigger a repaint which might get into an infinite loop.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018