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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple instances of form 1

Status
Not open for further replies.

shmilyca

Programmer
Apr 30, 2006
63
US
Hi,
My app resides in system tray. When it runs firsttime it loads 6-8 instance of a form say TForm1 (nonmodal) reading values from database and displaying it.
Form1.Create & Form1.Show methods are executed from another form. Right now if you run application you see first window is loaded...then it read second record from database and display second form...third form ..like wise all forms. Even though all this happens fast its irritating poping one window after another.
How can I Load all forms in memory..and show all forms or hide all window in just one action?
Another question is if there are many forms reside in memeory would it cause memory problems?
 
Create all forms and store them in a TList.
Then, when all forms are created, loop the list and show them all in a flash...

Code:
  List := TList.Create;
  ...

  // Record 1
  List.Add(TForm1.Create(application));
  ...
  ...
  ...
  // Record 5
  List.Add(TForm1.Create(application));

  for nIdx := 0 to List.Count-1 do
    TForm(List[nIdx]).Show;

  ...
  List.Free;



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
 
I appriciate your time & help.When I tried it.I got Access Violation Error..How to close all windows in one action? Any otherthing you can think of?

Thank you
 
I would say lots of forms in memory is not a good idea.
Is your application a MDI (multi document interface)? If so there are ways of closing all the child forms neatly.


Steve: Delphi a feersum engin indeed.
 
No dont have MDI Interface..Please let me know if you find anything.
 
The List should then be global and run the following (..or similar) for-loop to close them:

If the OnCloseQuery eventhandler returns false, the Form cannot be closed, therefore the f.CloseQuery query.

Code:
var
  F: TForm1;
  nIdx: Integer;
begin
  for nIdx := List.Count -1 downto 0 do
  begin
    F := TForm1(List[nIdx];
    if F.CloseQuery then
    begin
      F.Close;
      F.Free;
      List.Delete(nIdx);
    end;
  end;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top