Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2004, 11:43 PM
Chesso Chesso is offline
Senior Member
 
Join Date: May 2004
Location: Sydney, Australia
Posts: 1,199
Default Form create/destroy?

Other forms that i show/hide from my main one id like to create and destroy instead so they aren't always loaded unless i really need to.

how would i go about doing this?
Reply With Quote
  #2  
Old 12-11-2004, 12:28 AM
simor simor is offline
Senior Member
 
Join Date: Nov 2002
Posts: 307
Default RE: Form create/destroy?

read this:

[link]http://delphi.about.com/od/beginners/l/aa070203a.htm[/link]

simon
Reply With Quote
  #3  
Old 12-11-2004, 01:54 AM
Chesso Chesso is offline
Senior Member
 
Join Date: May 2004
Location: Sydney, Australia
Posts: 1,199
Default RE: Form create/destroy?

ummm ok i hope i understood it in someway is this ok to use?

When i want to show the form.
Code:
Procedure TFrmMain.MMWSSecurityClick(Sender: TObject);
Var
 Form: TFrmSecurity;
Begin
    Form := TFrmSecurity.Create(Self);
    MMWSSecurity.Enabled := False;
    Form.Show;
End;
And when i want to close it.
Code:
Procedure TFrmSecurity.BtnCloseClick(Sender: TObject);
Begin
    FrmMain.MMWSSecurity.Enabled := True;
    Self.Release;
End;
Reply With Quote
  #4  
Old 12-11-2004, 03:15 AM
simor simor is offline
Senior Member
 
Join Date: Nov 2002
Posts: 307
Default RE: Form create/destroy?

hmm do you have to invent your own code ? I see you want to have modeless forms so just follow the example. Create the form using Show (as you did) and close it using the OnCloseForm event and instead of calling release do a close - I dont know if your method is wrong but if it is possible - follow the correct example.

regard
simon
Reply With Quote
  #5  
Old 12-11-2004, 04:43 AM
rsawoseyin rsawoseyin is offline
Senior Member
 
Join Date: Nov 2001
Posts: 515
Default RE: Form create/destroy?

An efficient way to manage forms in an application is to create an instance of the form when needed, show it as a modal form using ShowModal(), and Release it when through with it. The steps are as follows:

1) Apart from your main form, do not autocreate any form unless your program logic absolutely requires it.
2) Using your own example, I would do this:
Code:
Procedure TFrmMain.MMWSSecurityClick(Sender: TObject); var 
  Form: TFrmSecurity; 
begin 
  Form := TFrmSecurity.Create(Self); 
  // You can set any properties of Form here, e.g.
  // Form.Caption:='Security settings';
  if (Form.ShowModal()=mrOk)     // Show form until done
      begin
        // Possibly save values that are set in Form.
      end
  Form.Release();   // Destroy and free memory
end
Raph Awoseyin
Port Harcourt, Nigeria
Reply With Quote
  #6  
Old 12-11-2004, 03:08 PM
Chesso Chesso is offline
Senior Member
 
Join Date: May 2004
Location: Sydney, Australia
Posts: 1,199
Default RE: Form create/destroy?

Simor so you think i should call Form.Close for the button to close the form and just use what was suggested in that article for the OnClose event of the form?
Reply With Quote
  #7  
Old 12-11-2004, 03:13 PM
Chesso Chesso is offline
Senior Member
 
Join Date: May 2004
Location: Sydney, Australia
Posts: 1,199
Default RE: Form create/destroy?

In the article for closing the form with a button it just releases it like i said so what's the point in an OnClose event?
Reply With Quote
  #8  
Old 12-11-2004, 03:23 PM
simor simor is offline
Senior Member
 
Join Date: Nov 2002
Posts: 307
Default RE: Form create/destroy?

It seems your way is working, and maybe it's the same thing -
since "self" is the frmsecurity, and you also release it so whats the point in doing close and puting that code in onclose ? maybe there is no point ?
-sorry

simon
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 04:41 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.