Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Showmodal and ModalResult

728 views
Skip to first unread message

Crispin Chapman

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

I have a form that I ShowModal and store the ModalResult. On the form are
two buttons (Ok & Cancel) with ModalResults set to mrOk & mrCancel. This is
fine.

Now I want to do some code in the OnClick event for the Ok button and not
allow exit in some conditions.

The problem I have is this:
If I do any code in the OnClick event for mrOk, mrCancel is returned as the
modal result. If I don't do any code, mrOk is returned.

???

How do I achieve this, and why is mrCancel being returned when the
ModalResult is set to mrOk?

mks...@ibm.net

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Crispin,
Within the code for the Ok button try
if (not what i want) then
exit;

that will stop the default processing of the OnClick event and
stop the form from closing. If you want to allow the form to close,
but not return mrCancel, try this:
if(not what i want) then
ModalResult := mrNone;
Close;
end;
I Hope this helps.
Good Luck,
Mike


Xavier Pacheco (TeamB)

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

I usually handle this by not assigning a modal result to the button
except at run-time in the OnClick event. Therefore my OnClick events
usually look something like:


if Validate then
ModalResult := mrOk
else
{ do something else}

--- x
Xavier Pacheco (TeamB)
Visit us at:

www.xapware.com/xmas.htm

Sorry but TeamB cannot answer support questions received via email.

Peter Below

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Crispin,

set the forms ModalResult to mrNone in your handler to prevent the form from
closing. If you see mrCancel returned when the OK button is clicked it has to
be something you do in your code that is causing this, it certainly does not
happen on its own.

Peter Below (TeamB) 10011...@compuserve.com)

0 new messages