Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2014, 06:26 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default Modal form refusing to close

I have a form that is opened from the main form through
Code:
 
 ImplementedForm.ShowModal;
On the ImplementedForm itself, I have a MonthCalendar component called ImplementedMonthCalendar that is set to align to alClient so that it takes up the full client area on the form.

Basically when someone selects a date, it must save that date, and close the form, returning to the calling form.
Because I don't want the form to close when someone clicks on the arrow on the MonthCalendar component to go backwards or forwards in months, but only when they select an actual date, I have put the code to save the date and close the form in the OnDoubleClick event instead.

Removing all other code from the event, and still only having the following, the form still refuses to close, I eventually have to click the cross itself to close the form. I've tried the following on the OnDoubleClick event without it working.

Code:
 
 ImplementedForm.CloseModal();
and...

Code:
 
 ModalResult := mrOk;
If I put the ModalResult := mrOk in the OnClick (single) event, then it closes the form.
Can anyone offer me some help please?
Reply With Quote
  #2  
Old 10-10-2014, 06:46 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 840
Default

Instead of:
ImplementedForm.CloseModal;
try this:
ImplementedForm.Close;
In my opinion, forcing the user to select the date with doubleclick is wrong. You should put two buttons(bOk, bCancel).
Reply With Quote
  #3  
Old 10-10-2014, 07:50 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

I tried in the MonthCalendar DblClick event
Code:
 
 ImplementedForm.Close();
but it doesn't work.

The reason to not having 2 buttons, the user was looking for a minimal clicking option.
I previously had it that he selects the date, then the OnClose event would store the date for further use. However he asked if I could rather make it when he clicks it once, it closes straightaway. However because of the reason to change months already noted, I decided to do the double-click option to select and close the form.
Reply With Quote
  #4  
Old 10-10-2014, 08:04 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 840
Default

Quote:
I previously had it that he selects the date, then the OnClose event would store the date for further use. However he asked if I could rather make it when he clicks it once, it closes straightaway. However because of the reason to change months already noted, I decided to do the double-click option to select and close the form.
Ok. If your client is happy with this, it's fine by me.

Quote:
I tried in the MonthCalendar DblClick event:
ImplementedForm.Close();
but it doesn't work.
Yes it does! I just run a few test! Can you please post the whole ImplementedForm.pas? Do you have code on formclose event for example?
Reply With Quote
  #5  
Old 10-10-2014, 08:18 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

This is the complete unit.
I am using Delphi XE3.

Code:
 
 unit Implemented;
 interface
 uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Data.DB,
  Data.Win.ADODB, DateUtils;
 type
  TImplementedForm = class(TForm)
    ImplementedMonthCalendar: TMonthCalendar;
    IDLabel: TLabel;
    MySQLADOQuery: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure ImplementedMonthCalendarDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 var
  ImplementedForm: TImplementedForm;
 implementation
 {$R *.dfm}
 uses Status;
 procedure TImplementedForm.FormCreate(Sender: TObject);
begin
 MySQLADOQuery.ConnectionString := 'FILE NAME=c:\ProductionDB\MySQLMaster.udl';
 ImplementedMonthCalendar.Date := today;
end;
 procedure TImplementedForm.ImplementedMonthCalendarDblClick(Sender: TObject);
begin
 ImplementedForm.Close();
end;
 end.
Reply With Quote
  #6  
Old 10-10-2014, 08:21 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

The MysqlADOQuery is for when I update the date to a MySQL database, I have removed all other code not used in this test, I could have removed this too, only saw it afterwards.

When I double click to select the date and close the form, the form flashes once, but then stays open.
Reply With Quote
  #7  
Old 10-10-2014, 08:38 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 840
Default

I don't have XE3, but I do have D7, D2007, D2009, XE4, Lazarus and I cannot reproduce the error.
Try to close that ADOQuery on formclose, if still doesn't work as it should, please create a separate application with to forms and test it there.
Reply With Quote
  #8  
Old 10-10-2014, 09:51 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

I can add the code for the AdoQuery into the formclose, no problem. However I can't get the form to close, that is my problem.
I'll do a reboot, maybe tha's all it needs.
Strange problem...!
Reply With Quote
  #9  
Old 10-10-2014, 09:55 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 840
Default

Try this:
Code:
procedure TImplementedForm.ImplementedMonthCalendarDblClick(Sender: TObject);
begin
  PostMessage(ImplementedForm.Handle, WM_CLOSE, 0, 0);
end;
Reply With Quote
  #10  
Old 10-10-2014, 10:21 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

Sadly it didn't work either!
I'm going to try recreate the form and test it.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.