Solved

Modal windows..

Posted on 2001-09-03
18
255 Views
Last Modified: 2010-04-06
I want to show a form with which the user is to type in some details and click a save button, like a dialog box. I need this form modal towards its parent form (which btw. is a TFrame). The TForm.ShowModal function disables ALL of the windows in the entire application, but I only want to disable the parent, as told. I also need the parentform (frame) to stop processing any further code until the dialog box is closed.

How can this be done?
0
Comment
Question by:sageryd
18 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6450767
You could add a window message handler to the parent form which ignores (or beeps) on any message when a certain condition (e.g. client window is open) is true.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6450777
But I need it to halt code execution until the client window has closed.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6450790
You cannot halt code execution and at the same time have only the parent window being locked. However, if you make sure that the parent window will not process messages, it will pretty much behave as if it was "dead" and not execute and OnClick etc. code.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6450805
My code looks like:

var
  MyForm: TMyForm;
begin
  MyForm := TMyForm.Create(nil);
  MyForm.Edit1.Text := MyDataSet.FieldByName('whatever').AsString;
[...]
  MyForm.Show; //(modal)

  //after close:
  MyDataSet.Edit;
  MyDataSet.FieldByName('whatever').AsString := MyForm.Edit1.Text;
  MyDataSet.Post;
end;
0
 
LVL 3

Expert Comment

by:oraelbis
ID: 6450913
It seems that you can't access to MyForm.Edit1.Text after MyForm closing. If it is, try this code:


type
  TMyForm = class(TForm)
    ...
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    whateverText:String;
  end;

var
  MyForm: TMyForm;

...
try
  MyForm := TMyForm.Create(nil);
  MyForm.Edit1.Text := MyDataSet.FieldByName('whatever').AsString;
  if MyForm.ShowModal=mrOk then
     MyDataSet.FieldByName('whatever').AsString:=MyForm.whateverText;
finally
  MyForm.Free;
end;

procedure TMyForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Self.whateverText:=MyForm.Edit1.Text;
end;
0
 
LVL 1

Author Comment

by:sageryd
ID: 6450926
Please read the question before answering :)  That was not the problem.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6450933
Of course I would put a FreeAndNil(MyForm) after the DataSet posting, but I thought it was irrelevant to this question.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6450943
And, oraelbis,

try
 MyForm := TMyForm.Create(nil);
  MyForm.SHow;
etc..
finally
  MyForm.Free;

...is incorrect as if the form would fail to create the form in the first place, it would try to free itself and thus generate an error. Just a little hint. No offense.. I bet it was just a typing mistake. :)

Cheers!
0
 
LVL 1

Author Comment

by:sageryd
ID: 6450950
Sorry for that word error. "form" doesn't create, "it" does. Nevermind. Give me an answer..! *dying*
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 14

Expert Comment

by:AvonWyss
ID: 6451039
I thought of something like this (Form1 is the pseudo-modal form):

     TForm1 = class(TForm)
     private
          FLockingForm: TForm;
          FLockingCloseEvent: TCloseEvent;
          procedure ShowClientAndLock(AForm: TForm);
          procedure LockingCloseNotify(Sender: TObject; var Action: TCloseAction);
     protected
          procedure WndProc(var Message: TMessage); override;


var
     MyForm: TMyForm;
begin
     MyForm := TMyForm.Create(nil);
     MyForm.Edit1.Text := MyDataSet.FieldByName('whatever').AsString;
[...]
     ShowClientAndLock(MyForm);
end;

procedure TForm1.ShowClientAndLock(AForm: TForm);
begin
     Assert(not Assigned(FLockingForm)); //only one lock allowed
     Assert(Assigned(AForm)); //must not be NIL
     FLockingForm:=AForm;
     FLockingCloseEvent:=FLockingForm.OnClose;
     FLockingForm.OnClose:=LockingCloseNotify;
end;

procedure TForm1.LockingCloseNotify(Sender: TObject; var Action: TCloseAction);
begin
     Assert(Sender=FLockingForm);
     if Assigned(FLockingCloseEvent) then
          FLockingCloseEvent(Sender,Action);
     if Action in [caHide,caFree] then begin
          FLockingForm.OnClose:=FLockingCloseEvent;
          FLockingForm:=nil;
     end;
end;

procedure TForm1.WndProc(var Message: TMessage);
begin
     if Assigned(FLockingForm) then
          if Message.Msg=WM_PAINT then
               inherited
          else if Message.Msg=WM_SETFOCUS then begin
               MessageBeep(0);
               FLockingForm.SetFocus;
          end;
end;


When the client window is successfully closed (I'd suggest to use an OnClose event and to set the Action variable to caFree for automatic freeing of the window), the "parent" will become active again.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6451046
Cool. I'll try that, tomorrow.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6451316
why not simple disable the tframe?
0
 
LVL 1

Author Comment

by:sageryd
ID: 6452991
Because I need to halt code execution.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6453104
Avon, your code doesn't halt the code execution in the parent form, does it?


var
    MyForm: TMyForm;
begin
    MyForm := TMyForm.Create(nil);
    MyForm.Edit1.Text := MyDataSet.FieldByName('whatever').AsString;
[...]
    ShowClientAndLock(MyForm);
  MyDataSet.FieldByName('whatever').AsString := MyForm.Edit1.Text;
  FreeAndNil(MyForm);
end;


...wouldn't work would it?
0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 50 total points
ID: 6453322
sageryd, as explained beforer, code executeion CANNOT and MUST NOT be halted. However, the form will be locked until the other form has been closed. make a OnClose function for the "child" form which does this:

procedure TMyForm.FormClose(Sender: TObject; var Action: TCloseAction);
    MyDataSet.FieldByName('whatever').AsString := Edit1.Text;
    Action:=caFree;
end;

After this code is executed, the parent form will "unlock" itself.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6892982
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11756739.html
http://www.experts-exchange.com/questions/Q.20012038.html
http://www.experts-exchange.com/questions/Q.20015074.html
http://www.experts-exchange.com/questions/Q.20071728.html
http://www.experts-exchange.com/questions/Q.20075938.html
http://www.experts-exchange.com/questions/Q.20086694.html
http://www.experts-exchange.com/questions/Q.20091498.html
http://www.experts-exchange.com/questions/Q.20110041.html
http://www.experts-exchange.com/questions/Q.20114710.html
http://www.experts-exchange.com/questions/Q.20127095.html
http://www.experts-exchange.com/questions/Q.11360917.html
http://www.experts-exchange.com/questions/Q.20136586.html
http://www.experts-exchange.com/questions/Q.20161465.html
http://www.experts-exchange.com/questions/Q.20170435.html
http://www.experts-exchange.com/questions/Q.20177789.html
http://www.experts-exchange.com/questions/Q.20251794.html
http://www.experts-exchange.com/questions/Q.20197428.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20090412.html
http://www.experts-exchange.com/questions/Q.20109565.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6893433
I think I provided a suitable answer to the question asked.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6899347
Sorry. Forgot all about this questions existance.

Happy easter
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now