TAdvEdit and TButton.Default

Hi.

Using Delphi DX and latest TMS ....

Default button (Button1.Default := true) does not trigger when focus is TAdvEdit.

Reproduce:
New - VCL app.
Put TAdvEdit and TButton on form.
Set Button1.Default to true.

implement ....

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage('beep :-)');

end;


Run - and press ENTER while focus is in AdvEdit1

Inside AdvEdit.pas ...
It looks as if GetFocus is called and compared to parent.handle.

Line 4712 ...

  if (Msg.CharCode = VK_RETURN) and FDefaultHandling and not IsPrev then

  begin
    // Take care of default key handling
    if (Parent is TWinControl) then
    begin
      if (GetFocus = Parent.handle) then
      begin
        PostMessage((Parent as TWinControl).Handle, WM_KEYDOWN, VK_RETURN, 0);
        PostMessage((Parent as TWinControl).Handle, WM_KEYUP, VK_RETURN, 0);
      end;
    end;
  end;


Why is the check with GetFocus needed?

I hope that someone can tell me how to use Default property of a button when focus is a TAdvEdit and you press ENTER.

This is because TAdvEdit has a feature that allows navigating to the next control when you press enter. If you want to disable this handling, set AdvEdit.DefaultHandling = false

Thanks Bruno :-)


It works!
Perhaps the property "DefaultHandling" should be moved from public to published instead?

in TAdvEdit.pas - line 2527 

  FDefaultHandling := ADVEDIT_DEFAULTHANDLING;

Since ADVEDIT_DEFAULTHANDLING is ONLY used here - we could comment line 2527 (or remove it completely - less code to maintain).
+ remove the declaration in line 1073 :   ADVEDIT_DEFAULTHANDLING : boolean = True;

if the desired initial value is true - then set it as default on then property 
    property DefaultHandling: Boolean read FDefaultHandling write FDefaultHandling default true;

But IMO a default value of false would ensure that "upgrading" older projects using other Edit components to TAdvEdit has a better chance of "running" as intended.

For now I have to add code to override the "obsolete" code in TAdvEdit.
I hope you can see this. :-)

I understand your remark, but changing this will also affect users with existing projects counting on the default automatic handling of the return key. So, for backwards compatibility, this default setting must remain as it is. 

I can see your point.
But at least make the property published then :-)

Ok, in the next update this will be promoted to published level.

Thank you Bruno - much appreciated :-)


Great support!