I have my custom class that extends TEdit:
TMyTextEdit = class (TEdit)
private
fFocusNextOnEnter: Boolean;
public
procedure KeyUp(var Key: Word; Shift :TShiftState); override;
published
property FocusNextOnExnter: Boolean read fFocusNextOnEnter
write fFocusNextOnEnter default false;
end;
In The KeyUp procedure I do:
procedure TMyTextEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if FocusNextOnExnter then
if Key = VK_RETURN then
SelectNext(Self as TWinControl, True, false);
end;
But it isn't moving focus to the next control. I tried to
if Key = VK_RETURN then
Key := VK_TAB;
but it isn't working either. What am I missing?
SelectNext
selects next sibling child control, ie. you need to call it on your edit's parent:
type
THackWinControl = class(TWinControl);
if Key = VK_RETURN then
if Assigned(Parent) then
THackWinControl(Parent).SelectNext(Self, True, False);
Here's the PostMessage approach (uses Messages) for the record :)
procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if FocusNextOnExnter then
if Key = VK_RETURN then begin
PostMessage(GetParentForm(Self).Handle, wm_NextDlgCtl, Ord((ssShift in Shift)), 0);
Key := 0;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With