Topic: Cancel Form Close

Is there any way to cancel a form close procedure?

I want to force the user select or enter text in a box. My form has an autosave button called when the form is closed. Hence, is the user does not select a value from a combobox or enter text in a text box, they will be empty.

Thanks indeed.

Have a Blessed Day...

Re: Cancel Form Close

Hello boulenajm

If I understood your question correctly, you don't want to save a field that is empty. That's right ? In this case, here's how I do it:

Prevent a field from being empty

When creating the database, you can create a NOT NULL field to prevent its value from being empty.

You can also use a script behind the OnClick event of the SaveRecord button.

Example:

procedure Form2_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
     if (Form2.Edit1.Text = '') or (not Form2.CheckBox1.Checked) or (Form2.ComboBox1.dbItemID = -1) then
     begin
         ShowMessage ('Please fill in the fields');
         Cancel: = True;
     end;
end;

Here we take the opportunity to check that a CheckBox is checked.

Hope this can help you

JB

Re: Cancel Form Close

Thanks JB, I appreciate the reply, but I need to cancel the close action, if the user clicks the X on top of the window, since I am using autosave (calling a button action to automatically save the values), I am able to show an error, but it still saves the empty fields.

Also, one of the fields I am trying to save is a relationship, the software does not allow null default values for relationships... I think the best and easiest way would be just to cancel the close from being closed...

Re: Cancel Form Close

Hello boulenjam

So you to deactivate X button, you can to the Object Inpector and, from BorderIcon property, you uncheck biSystemMenu option
JB

Re: Cancel Form Close

Awesome. Thanks indeed JB, I truly appreciate it... smile This will really help.