Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 175895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:46:48+00:00 2026-05-11T13:46:48+00:00

In one part of the application I’m working on, there is a form control

  • 0

In one part of the application I’m working on, there is a form control that does validation on reception of the CMExit message, which is exactly how the Delphi documentation says to do it (this code sample is from the Delphi Help files):

procedure TDBCalendar.CMExit(var Message: TWMNoParams); begin  try   FDataLink.UpdateRecord;                          { tell data link to update database }  except   on Exception do SetFocus;                      { if it failed, don't let focus leave }  end;  inherited; end; 

The purpose of this is to perform the validation as soon as the control loses focus. So, for example, if I were to click on the OK button, the form control would lose focus, this method would run and on an exception would set the focus back to that form control. (Thus the ‘click’ event on the OK button would never go through and the dialog would never close).

The problem I’m having is that this form control is inside a modal dialog window. Clicking OK does indeed send the CMExit message and causes the record to update (and validation to occur). However, pressing Enter while in the form control causes the modal dialog to close without sending the CMExit message. It’s as if the form control never ‘loses focus’. This means that not only does the dialog close without the form actually validating the data, but the data set isn’t updated, either.

Given this problem, where is the best place for me to place my dataset updating/validation code? I could move it up to the dialog form itself and implement it in the OnCloseQuery handler, but this would mean that the logic is duplicated in both the form control and on the form itself. (The form control is used in other places, and I want to avoid changing its behaviour).

(I speculate that CMExit isn’t triggered because the control never actually does lose focus. The form is closed, but the form control still ‘has focus’ on the closed form.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:46:49+00:00Added an answer on May 11, 2026 at 1:46 pm

    Closing a form does not necessarily fire the on-exit event of a TControl. The user could hit Alt-F4, for example.

    I’d suggest moving the validation to a separate proc, and call that separate proc from both the on-exit and on-close events.

    The below code should work without too much modification:

    function TDBCalendar.UpdateSuccessful: boolean; begin   { tell data link to update database }   { if successful, return True, else return False }   { this function must be Public if a form is gonna check this value }   Result := True;   try     FDataLink.UpdateRecord;   except on Exception do     Result := False;   end;   inherited; end;  procedure TDBCalendar.CMExit(var Message: TWMNoParams); begin   //if not valid, then don't let them leave   if not(UpdateSuccessful) then begin     SetFocus;   end; end;  /////////////////////////////////////////// //on the form that contains your control... ///////////////////////////////////////////  procedure TMyForm.FormClose(Sender: TObject; var Action: TCloseAction); begin   //if not valid, then don't let them close the form   if not(dbcal.ControlIsValid) then begin     Action := caNone;   end   else begin     inherited;   end; end; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Ruby web Application that uses the Net::FTP library. One part
I've got a WinForms application that I am working on. There is one small
I am working with a node.js application that uses Facebook APIs. In one part
Should libraries that the application relies on be stored in source control? One part
I have an ASP.NET MVC application that has one part where I dont really
We have an application that is being moved to .NET. One part of the
I have an application that uses Hibernate for its domain objects. One part of
i have created an mvc3 web application that uses forms based authentication. one part
I am writing an application which tests email addresses, for one part of this
I am working on an application written in C. One part of the application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.