Multi forms: how to change the showed form lazarus / 13-General ---------------------------------------------------------------------- Stefano · 2006-04-20 21:53 Hello and excuse me for my bad English. I have a multi-forms program with Lazarus and this is ok. I have a main form with a menu, every item of the menu loads a different form. The problem is that I'dd need to have more forms active in the same time. So, as Lazarus doesn't support MDI Forms yet, I ask you the best way to give to the user the possibility to easy pass from a form to another without close the first form. In MDI Application, it is possible choosing the form by the Window item of the Menu. I'd like to have something like this in Lazarus. Is it possibile? My program is a book-keeping type, then when the user insert the general ledger, it could be necessary to have at the same time the form for insert new customers/suppliers, the form to show a balance, the form to set some data, etc.. What can I do for doing that? If this is not possibile yet, is it possible at least to put every form in the TaskBar, so the user can choose the form from the Task Bar? Thank you very much if you can help me. Best Regards, Stefano ---------------------------------------------------------------------- Anonymous · 2006-04-22 19:13 In the menu button click do something like this: procedure buttonclick(sender:tobject); var newform:tnewform; begin  newform:=tnewform.create(nil);  newform.show; end; This will create a new form each time you click the button.  Each form wil become active when you select it.  When you close the main menu form it will close all the children it created. I am writing a similar program (inventory tracking).  I try to keep all my information on one form using tabs.  But in general I have customer, vendor, and inventory open all at once. John ---------------------------------------------------------------------- Anonymous · 2006-04-22 21:34 Thank you for your reply, but it is what I've already done. But when the user clicks the menu button the new form is showed, ok, but the problem is when from that form the user wants to go back to the main form (or to another already active form). He can choose no form. He can try to resize the form, and see the form "under" this, and if it's not the form he wants, he has to resize even this and so on. This isn't very nice but, above all, it's hard difficolut to return to the orginl form. This because on the Task Bar is showed only one program, for all the opened forms. FormStyle is setted to fsNormal, ShowInTaskBar is setted to stDefault. In spite of this, as I've said before, in the TaskBar I find only one program, even the opened forms are many. If I set ShowInTaskBar to stAlways things are better, in this case every form as its place in the Task Bar, but then if another form (e.g. a form for finding data form a database or simpy a MsgDialog) is opened as modal, the modal form is showed on the main (first) form and not on the applying form... I don't know why. fsSplash and fsStayonTop setted on the "child" forms crash (particulary when I send data to the Db or RollBack the transaction, I use UB and FbDataSet). I've Lazarus 0.9.13 on Windows 2000 Professional. Thank you if you can help me for allow the user to return back to the main form and for be able to choosing and moving among the opened forms. Best regards, Stefano ---------------------------------------------------------------------- eric · 2006-04-23 09:54 Quote from: "Anonymous"procedure buttonclick(sender:tobject); var newform:tnewform; begin  newform:=tnewform.create(nil);  newform.show; end; That's a terrible bit of code! Newform is a local variable and goes out of scope as soon as you leave the buttonclick procedure. Each time you click the button another instance of the form will be created and will never be destroyed. You should never use a local variable to create an object, unless that instance of the object is destroyed before you leave the procedure. Eric ---------------------------------------------------------------------- Bart · 2006-04-23 10:26 Quote from: "eric" You should never use a local variable to create an object, unless that instance of the object is destroyed before you leave the procedure. Eric I do not agree. If you useCode: [Select]procedure TNewForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin   Action := caFree; end; in the created form, it will be freed when you close it (if I understand it correctly). This is what I used to do in MDI forms. In my Html editor I now use a diffrent approach. I create the object at runtime as above, but do not use nil as it's owner, but an (also at runtime created) TabSheet. When I close the TabSheet, I free/destroy all the objects that it owns. So, all object created this way are destroyed when I do no longer need them (or close the app). It's just a matter of keeping track of what you create... Bart ---------------------------------------------------------------------- itsols · 2012-09-21 14:36 Hi, after some years, we still don't have a proper MDI infrastructure. Anyway, I was wondering if your statement Action:= caFree; is correct... I got an error trying this but when I changed it to CloseAction, it was fine. I'm new to this and I hope you'll correct me if I'm wrong. ---------------------------------------------------------------------- reinerr · 2012-10-29 02:42 Yes, CloseAction is the correct default syntax - maybe that was different 6 years ago. In any case you can change the parameter names (after they have been auto generated) - as usual the declaration and implementation just need to match. Code: [Select]procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin   CloseAction := caFree; end; PS. Sorry for answering this port 1 month late but I like completion.