A modal form does not close during (dcl-Form-Close), but after the function returned and the form finishes processing all the Windows messages for the form. In the meantime, some other event (either your own or a Windows message handler) can supersede your exit code. For instance, your mouse down event is likely followed by a mouse-up event. That event handler or message handler might be superseding your exit code (for instance, if the mouse-up occurs over the cancel button, which is always return code 2).