Recent

Author Topic: How to trap the user in a TEdit untill condition(s) met?  (Read 4077 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
How to trap the user in a TEdit untill condition(s) met?
« on: August 05, 2011, 02:17:59 pm »
Dear Forum people,

On a TEdit Box, is there a way to trap the user in it once he clicks into it to edit it, so that the mouse can not move (or other mechanism) trapping the user there until code liberates the mouse? Code checking would be by a procedure OnEditingDone, which returns focus to the TEdit in question if conditions not met, or liberates the mouse if met.

Thanks!




Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11789
  • Debugger - SynEdit - and more
    • wiki
Re: How to trap the user in a TEdit untill condition(s) met?
« Reply #1 on: August 05, 2011, 02:32:37 pm »
Within your app, you can disable all other inputs. Or just move the focus back.

Stop the mouse from moving, or block the user to switch to another app. I don't know. For windows search MSDN (google).
But I would not advice it. No one I know would ever use an application that tries to do that.

And I don't think you can stop the user from ctrl-alt-del => and kill your app.

If you want to write a software for a company network, to enforce company policies, then you should deinfe appropriate policies for the windows user accounts etc...

Bart

  • Hero Member
  • *****
  • Posts: 5609
    • Bart en Mariska's Webstek
Re: How to trap the user in a TEdit untill condition(s) met?
« Reply #2 on: August 05, 2011, 02:34:56 pm »
You can try using the OnExit event handler to check if the input is correct, and if not transfer focus to the edit again.

Pseudocode:

Code: [Select]
procedure Edit1OnExit(Sender: TObject);
begin
  if not CorrectInput(Edit1.Text) then Edit1.SetFocus;
end;

This is not guaranteed to work on all widgetsets AFAIK.

You might also consider using a TMaskEdit, which uses a similar approach if validation fails.

Bart

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to trap the user in a TEdit untill condition(s) met?
« Reply #3 on: August 05, 2011, 03:04:59 pm »
Thanks Bart.

I agree that locking the mouse is extreme high level and probably not allowed nor adviced.

I rather meant like maybe there is a way to automatically lock entry to any other component.

Like if it were music, that component "soloes". I.e. Only it plays.

And the mouse can move freely, but can not activate other components.

On my limited learning, I have not seen a way to prevent leave the TEdit and go click another button elsewhere, or enter another TEdit, or box.

And that's what I was interested in knowing if there is such a way.

Thanks!

Dick, from the internet

  • Full Member
  • ***
  • Posts: 198
Re: How to trap the user in a TEdit untill condition(s) met?
« Reply #4 on: August 05, 2011, 07:47:03 pm »
You can disable all controls on the form until the entry conditions are met, using a verification function as mentioned by Bart:

Code: [Select]
procedure TForm1.Edit1EditingDone(Sender: TObject);
begin
   if Edit1.Text = 'your text' then
    begin
      Edit2.Enabled := True;
      Edit2.SetFocus;
    end
  else
    begin
      Edit1.SetFocus;
      Edit2.Enabled := False;
    end;

end;

geno.

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to trap the user in a TEdit untill condition(s) met?
« Reply #5 on: September 05, 2011, 10:36:16 am »
Thanks Geno.

 

TinyPortal © 2005-2018