Recent

Author Topic: Modal form open  (Read 6287 times)

andre72

  • New Member
  • *
  • Posts: 33
Modal form open
« on: May 07, 2008, 07:53:07 pm »
I have a modal form open, ie a form opened from the main form using ShowModal.

Is there any way to trap a click on the main form? The system does - since the click triggers a beep.

Can it be done in Lazarus - running in Windows, Linux or Mac?

Thanks

A.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: Modal form open
« Reply #1 on: May 08, 2008, 08:34:00 am »
From http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tcustomform.showmodal.html:
Quote
Show this form as modal - ie control cannot be resumed by another form until the current form is closed

When a modal form is shown, the owner/parent (the one you pass to Create, probably Self) can't receive any control until it's closed. That's the behaviour of a modal form. For your needs, it's better to use 2 independent forms.

andre72

  • New Member
  • *
  • Posts: 33
Re: RE: Modal form open
« Reply #2 on: May 08, 2008, 09:57:02 am »
Quote from: "Leledumbo"
From http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tcustomform.showmodal.html:
When a modal form is shown, the owner/parent (the one you pass to Create, probably Self) can't receive any control until it's closed. That's the behaviour of a modal form.

Exactly. However, the Operating System _does_ catch the click. My question was, is there any way to get at it.
Quote
For your needs, it's better to use 2 independent forms.

Maybe. I cannot think of a workaroung at this point in time.

Thanks

A.

Yurgel

  • New Member
  • *
  • Posts: 16
Re: RE: Modal form open
« Reply #3 on: May 09, 2008, 11:24:07 am »
Quote from: "andre72"

Exactly. However, the Operating System _does_ catch the click. My question was, is there any way to get at it.


Under Win32 mouse events (like any others) are traced by messages. So you can write a so called hook, and insert in the system's hook queue. Anytime when any mouse event is triggered, your hook (callback routine, actually) will be called. There you can determine where exactly mouse was pressed, do something you need, and pass a message along to other hooks.

I'm not sure that POSIX systems have similar possibilities. But honestly, even under Win32 such approach does not seem to be quite logical.

The best way, to my point of view, is to simulate modal behavior of the form in code. Allow other forms to receive mouse clicks, and in standard OnClick events, after doing the things you need, return focus to the previous form.

andre72

  • New Member
  • *
  • Posts: 33
Re: RE: Modal form open
« Reply #4 on: May 09, 2008, 11:43:31 am »
Quote from: "Yurgel"

The best way, to my point of view, is to simulate modal behavior of the form in code. Allow other forms to receive mouse clicks, and in standard OnClick events, after doing the things you need, return focus to the previous form.


Thanks, I'm on my way to doing this.

FYI, I'm writing an app for unexperienced, computer illiterate users, who tend to click all over the place, do not understand and grow extremely frustrated when nothing happens....

Yurgel

  • New Member
  • *
  • Posts: 16
Re: RE: Modal form open
« Reply #5 on: May 09, 2008, 11:59:38 am »
Quote from: "andre72"

FYI, I'm writing an app for unexperienced, computer illiterate users, who tend to click all over the place, do not understand and grow extremely frustrated when nothing happens....


Then, maybe, you don't need to trace events on all other forms. You need to trace the fact, that user tries to leave the current one. If so, you still can use ShowModal and add an OnDeactivate event,

Code: [Select]

procedure TForm1.FormDeactivate(Sender: TObject);
begin
  ShowMessage ('Please fill in data required!');
end;


Anytime user clicks anywhere on the screen, he will see your message. But he still will be able to launch other applications, or access start menu, for example.

 

TinyPortal © 2005-2018