Recent

Author Topic: TDateEdit and SelectNext(ActiveControl, False,True)  (Read 4982 times)

talorigomat

  • Jr. Member
  • **
  • Posts: 96
TDateEdit and SelectNext(ActiveControl, False,True)
« on: May 20, 2016, 12:41:46 pm »

I use the following code in a  TEdit and TLabelledEdit OnExit event
 
         Form1.SelectNext(ActiveControl, False,True)

This has  the effect of the focus not moving to the next control but remaining on the current control when the tab key is pressed.

The same code placed in a TDateEdit OnExit event doesn't have the same effect.  The focus moves to the next component when the tab key is pressed

Is this a bug in Lazarus, or should I use another way to accomplish the same thing for TDateEdits?
Lazarus 1.8.0Rc4, Windows 10

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: TDateEdit and SelectNext(ActiveControl, False,True)
« Reply #1 on: May 20, 2016, 02:26:22 pm »
TDateEdit is an embedded control, it's parent is a TCustomControl.
Look at the code that handles the Tab Key in the base class of TDateEdit how it is handled there, that may give you some clu how to solve this particular problem maybe.

Alternatively can't you just intercept the Tab Key?

Bart

shacsoft

  • Newbie
  • Posts: 1
Re: TDateEdit and SelectNext(ActiveControl, False,True)
« Reply #2 on: July 02, 2016, 01:33:13 am »
TDateEdit has their own "PerformTab"

I found these solution:

procedure TForm1.DateEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if ((key=Vk_Up))  then begin
    Key:=0;
    DateEdit1.PerformTab(false);
  end;
end;


u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: TDateEdit and SelectNext(ActiveControl, False,True)
« Reply #3 on: September 17, 2017, 05:23:17 am »
Hi all!

Apologies for writing here, but it can help anyone looking for a solution in the same place.

I don't know if it is a bug, but to set focus forward, TWinControl.PerformTab(True); doesn't work. I've found one alternative...

Need assign ControlsAll_OnEnter and ControlsAll_OnKeyDown to the controls events


Quote
var
    tLastFocused: TObject;  // <-- Save last TObject focused in the form // Private Variable


procedure TForm1.ControlsAll_OnEnter(Sender: TObject);
begin

  if Sender.ClassType = TEdit then begin
    tLastFocused := Sender;                                       // Register Last focused Object
  end else if Sender.ClassType = TDateEdit then begin
    tLastFocused := Sender;
  end else if Sender.ClassType = TComboBox then begin
    tLastFocused := Sender;
  end else if Sender.ClassType = TMemo then begin
    tLastFocused := Sender;
  end else if Sender.ClassType = TBitBtn then begin
    tLastFocused := Sender;
  end else begin
    // Disabled, only register some ClassType's
  end;

end;


procedure TForm1.ControlsAll_OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
var
  cDateEdit: TDateEdit;
  ctWinControl : tWinControl;
begin

  if (Shift = [ssAlt])  and ((key = VK_LEFT)) then begin                      // Setfocus to backward control

    if tLastFocused.ClassType = TDateEdit then begin
      cDateEdit := TDateEdit(tLastFocused);
      cDateEdit.PerformTab(False);
    end else begin
      SelectNext(TWinControl(tLastFocused), False, True);
    end;

  end else if (Shift = [ssAlt]) and ((key = VK_RIGHT)) then begin        // Setfocus to forward control

    if tLastFocused.ClassType = TDateEdit then begin
      cDateEdit := TDateEdit(tLastFocused);
      //cDateEdit.PerformTab(True);                                                    // <-- ¿Bug? // Don't work
      ctWinControl := FindNextControl(cDateEdit, true, true, true);
      //ShowMessage(ctWinControl .Name.ToUpper);
      ctWinControl.SetFocus;
    end else begin
      SelectNext(TWinControl(tLastFocused), True, True);
    end;

end;


« Last Edit: September 17, 2017, 05:25:39 am by u2o »

 

TinyPortal © 2005-2018