Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Reloading a form as designed by using code

Reloading a form as designed by using code

Reloading a form as designed by using code

Hey There,

I would appreciate help or advice. Please try to keep it as simple as possible, as I am not above average experienced with delphi. I'm using delphi 7 Professional and I would like to reload a form that I'm closing in the way I designed it, meaning clearing all the checkboxes etc to their designed state without having to type everything out. I have three forms that needs to be 'reloaded' every time one of the three in question is closed.

I am unable to find my answer via google for the past two hours.

Thank you in advance.

RE: Reloading a form as designed by using code

Are you wanting to do this when you're running your application? For example, the user opens form1 and fills in some information and then closes the form. They then open form1 again but all of the checkboxes and information are still showing from the first time they used the form - but you wanted to have the form to not show what the user typed the first time. Is that correct?

RE: Reloading a form as designed by using code

That is correct sir.

This is my scenario.
I'm writing a simple database program for the church to add members into the dbase. The user clicks on bkAdd which sets frmAddMember to Visible. This form contains a number of edits and checkboxes and bkNext. BorderStyle is single thus the user can close frmAddMember or click bkNext to continue to frmAddMember2 which has the same properties as frmAddMember, the last form frmAddMember3 has the same properties except for the buttons btnCancel and btnSave. All 3 forms have an OnClose procedure that sets the frmMainScreen to visible.

Now what I'm trying to do is the following:
If the user closes any of the frmAddMembers, I want it to clear all data back to their default state on all the forms. I would like to do the same after the user has clicked on btnSave, after my code has assigned the entered data to my record base.

Hope my explanation makes sense

RE: Reloading a form as designed by using code

Yes. Here is what I do:

CODE -->

procedure TForm1.Button1Click(Sender: TButton);
  fAddMember: TfrmAddMember;
  try try
    fAddMember := TfrmAddMember.Create(Application);
    on e:exception do begin

What you end up doing is creating a new instance of the form which will start up just as you saved it when you designed it.

RE: Reloading a form as designed by using code

I can't think of a quick and dirty way to do what you ask. Recreating the form from scratch is going to mean taking a performance hit and possibly annoying flicker. Your best bet would be to write a procedure in the form that resets all the control's values to their desired state. That option will also allow for the possibility of wanting a different reset value for a control than the initial value on down the line.

RE: Reloading a form as designed by using code

Thank you very much Djangman. May I continue in asking for a bit of a breakdown of the above code?

I see you are declaring a variable of type TfrmAddMember. Could you please explain your code? Sorry to be a bother, but I believe in understanding the code before implementing it, so that I actually learn the technique in stead of just have myself spoonfed.

RE: Reloading a form as designed by using code

When you create a form in Delphi the form's unit automatically creates a variable whose type is that form. It will auto automatically create an instance of that form unless you tell the program not to (Project, Options, Forms).


fAddMember := TfrmAddMember.Create(Application); 
This creates a new instance of TfrmAddMember and makes that form's owner the Application.


This makes that form appear to the user. Then the code within the form works as normal. The user fills out the form, clicks some sort of 'Save' button and the information is posted back to the database. When the user clicks Close the form will be closed and then:


This will destroy the form.

Search the web for dynamically created form and you'll get lots of examples.

RE: Reloading a form as designed by using code

one small remark here:

Djangman you got the exception handling wrong.
In your code sample the outer try finally has no sense since it will alwayes execute since you swallow the exception in the inner block, the correct order should be:


procedure test;

var obj : TObject;

 Obj := TObject.Create;
  on E: Exception do

What You See Is What You Get
Never underestimate tha powah of tha google!

RE: Reloading a form as designed by using code

Thank you, Daddy. Was coding from the hip, so to speak.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close