Mike surely is right,
I just want to add that it only addresses and only needs to address the second part of your requirements: "Not to be able to click anywhere outside of the form"
Many, including me, consider modal forms a mess. It hinders certain actions to run smoothly, like shutting down an application or Windows. And you might even think: Well, that's good. You can also put data integrity and security high without modal forms by using transactions when it comes to saving changes. And you can be slave to the needs of energy savings or even hardware protection in some cases, when it comes to emergency shutdowns and your app hinders them.
If you work with buffering and transactions, no dbf or cdx file can get corrupted by not focusing on an edit form.
And besides that constraint you also constrain the user to not use other forms to gain an information needed for the current edit. So in the end it may mean users cancel out to be able to exit the form and first gather information, which they will perhaps even note on a paper notepad to have them available when they finally are captured on a modal form.
Modal forms should be scarce and it's a little wink that messageboxes are modal, they are about really short but important interventions of a users workflow to ask importantye/no questions. They can be programmed to do so for unimportant questions, too, and seem nagging, but they really focus on a question with only a few options like yes/no, cancel/ok or sometimes een only confirmation with OK.
There are always exceptions to the rule and I may not question your need for a modal form, but you actually might want something softer. At least as long as there is nothing edited and nothing to be saved first, why should a user not go off elsewhere in other forms? There's no way to switch a form from modal to non-modal, though, this hasto be decided when the form starts, the WindowType is readonly when a form runs.
So what actually happens if a user clicks outside the current form?
This question hints at knowing the event model of forms. Well, the form then loses focus, so thiforrm.Lostfocus is triggered, followed by Thisform.Deactivate.
These events in that order should under some circumstances just be accepted and under other circumstances you could set focus to the last active control in form.deactivate, for example like this:
Code:
o = CREATEOBJECT('activeform')
o.KeepActive=.t. && for sake of demonstration
o.Show()
DEFINE CLASS Activeform as Form
ADD OBJECT text1 as textbox WITH top=32,left=32
ADD OBJECT text2 as textbox WITH top=64,left=32
KeepActive = .f.
LastActive = .null.
PROCEDURE Paint()
IF ISNULL(Thisform.LastActive) OR Thisform.LastActive<> Thisform.ActiveControl
Thisform.LastActive = Thisform.ActiveControl
Endif
Endproc
PROCEDURE Deactivate()
IF Thisform.KeepActive AND VARTYPE(Thisform.LastActive)='O'
Thisform.LastActive.SetFocus()
ENDIF
ENDPROC
ENDDEFINE
Now the KeepActive flag can be set .t. only when there is an urge to keep the focus, otherwise it can be kept at .f. or set back to .f. after that need for modal behavior is gone.
With all that said, the need for modal states should be very rare. An edited record surely does not qualify, if you program data modifications by the standard of transactions.
And even in case you need all changes to directly go into a DBF unbuffered and without transactions, you have never a need for a modal state from the perspective of protecting the changes of data, the work of the user and time spent on it. There is use for both extremes and anything in between, but none of them should need guarding by forbidding to leave the current form.
Also see QueryUnload and usual ways of having an automatic save action to allow unloads when there is an application or even a Windows shutdown.
And take into account changing applcications instead of changing focus to another form of the same application, do not trigger anything, even if your form is modal, it's only application modal, not system modal. And it's good that way, it's in the sense of the parallelism of using multiple things at once - against the odds of people not being able to do multi tasking. They are, even men.
Chriss