Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-06

WinControl.CanFocus

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen

Regarding issue:
http://bugs.freepascal.org/view.php?id=21708

I would like to fix the bug as proposed by Zoran Vu?enovi? and Ondrej Pokorny. Opinions?

The current behavior is compatible with Delphi. However it conflicts with even Embarcadero's own documentation which means it clearly is a bug in Delphi.
We should not replicate Delphi's bugs IMO.

The changed behavior would affect existing code, at least in theory. In practice the CanFocus method is useless, no code can use it for its intended purpose. Thus the implication would be very small.

Juha

Reply by email

Juha Manninen
to Juha Manninen

Another thing:
Paul changed documentation for this method in does it not show here? : http://lazarus-ccr.sourceforge.net/docs/lcl/controls/twincontrol.canfocus.html

I don't know the details of generating the documentation. Maybe it shows somewhere else. (?)

Paul's diff:
<!-- function Visibility: public -->
<element name="TWinControl.CanFocus">
<short>Is this control allowed to receive the focus?</short>
- <descr>A control can get the focus only when all of its Parents
- are Visible and Enabled.
- </descr>
+ <descr>A control can get the focus only when all of its Parents except the form are Visible and Enabled.
+While CanFocus checks all control parents it does not check whether a form control is placed on can have focus.</descr>
<errors/>
<seealso/>
</element>

Reply by email

Martin Frb
to Juha Manninen: Regarding issue: http://bugs.freepascal.org/view.php?id=21708 I would like to fix the bug…
Juha Manninen wrote 15 lines
Regarding issue: http://bugs.freepascal.org/view.php?id=21708 I would like to fix the bug as proposed by Zoran Vu?enovi? and Ondrej Pokorny. Opinions? The current behavior is compatible with Delphi. However it conflicts with even Embarcadero's own documentation which means it clearly is a bug in Delphi. We should not replicate Delphi's bugs IMO. The changed behavior would affect existing code, at least in theory. In practice the CanFocus method is useless, no code can use it for its intended purpose. Thus the implication would be very small.

There is a valid use case

   if HiddenForm.EditFoo.CanFocus then
     HiddenForm.ActiveControl := HiddenForm.EditFoo;
   HiddenForm.Show;
This currently works, because of the visibility of the form is not checked.
(same applies for a form with Enabled := False)

If code prefers setting ActiveControl over calling SetFocus, then the current behaviour makes sense.

Reply by email

Ondrej Pokorny
to Martin Frb
Martin Frb wrote 12 lines
There is a valid use case if HiddenForm.EditFoo.CanFocus then HiddenForm.ActiveControl := HiddenForm.EditFoo; HiddenForm.Show; This currently works, because of the visibility of the form is not checked. (same applies for a form with Enabled := False) If code prefers setting ActiveControl over calling SetFocus, then the current behaviour makes sense.

That is somehow true. Looking into the LCL sources, I now think it's not a good idea to change the current code.

But still it would be nice to have a second CanFocus version available in the LCL that could be used with SetFocus.

There are 2 options IMO:

1.) Add an optional parameter to CanFocus. Something like:
function CanFocus(const aConsiderWholeTree: Boolean = False): Boolean;

aConsiderWholeTree = False: current code
aConsiderWholeTree = True: check form as well

2.) Add a new CanSetFocus (or whatever name) function to TWinControl:
function TWinControl.CanSetFocus: Boolean;

that checks the form as well and prevents SetFocus exceptions.

----
I think the second is better, what do you think? Or do you think that CanSetFocus/CanFocus(aConsiderWholeTree) shouldn't be in the LCL at all?

Ondrej

Reply by email