Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close form in formshow 1

Status
Not open for further replies.

bbegley

Programmer
Apr 29, 2002
228
US
We needed to do some processing inside a form, and in some cases it is not necessary to show the user the form, so we want to just close it. You cannot call Close during formshow, so we had it set up with a timer and a boolean.

Just looked on google to see if there was a better answer and found this:

postmessage(self.Handle, WM_CLOSE, 0, 0);

which can be called during formshow.
 
you could also do your prossesing inside the dpr file and just not create the form if its not needed...
 
You could also perform the code in the oncreate event of the form instead of the onshow, however you will be limited in what you can do in reference to the form itself from this event,as it is, by definition, still being created.
 
A lot of the processing has to do with the creation of objects on the form (it's a calendar made out of frames) with a lot of database values being used to create the frames.
 
If the form is called with ShowModal, you could try to set the ModalResult to a non-zero value as the last step of the OnShow event. If this fails, create a reintroduced, overloaded version of the Show procedure, with a boolean parameter passed with var. After initializing, set the value of the boolean to true or false, depending on whether the form should be shown or not. If not, in the calling procedure/function, check the boolean, and call the close command. Cheers,
Nico
 
I'd have the processing in a separate method and have 2 calls to it, 1 in the FormShow and the other in the place where you don't need the form shown.

procedure TForm1.processStuff
begin
:
end;


procedure TForm1.FormShow()
begin
:
processStuff;
end;

:
//if form doesn't need to be shown
if blah then
processStuff
else Show;

Just on a side, there's always the Hide function for a form.
 
there are many diferent ways this could be done, bbegley were not telling you how to do it were just offering the viewers out there the many different options...
 
Something like: ask two programmers the same question and get three answers? Cheers,
Nico
 
I'm always glad to hear suggestions. All of the suggestions here were better than the timer/boolean setup we were using before.

This program is a payroll/timesheet program for police officers, and can be filled out on different laptops and network machines. Whenever they plug a laptop into the network, the first thing we do is synchronize the data to insure that they have not made different reports for the same day, and to get a single version of their data on the laptop and network. Most of the time we need to show them the sync screen. When they bring data on a floppy or CD to a laptop or network machine we also run the synchronize process and bring up the screen. While we could run the process from outside the form, all of the "day frames" are formatted and set up with the data we've processed, and serve as sort of a persistence layer that lets us decide if the user needs to see the screen or not. In hindsight, we could have set this up better, but for now the
postmessage(self.Handle, WM_CLOSE, 0, 0);
is very handy.
 
Or you could just do

Application.ProcessMessages;
Application.Terminate;
 
This last option would close the whole app, and not just the form! Cheers,
Nico
 
Sorry, thought you wanted that, just change the last line for frmWhatever.Close then.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top