Reset a Form!! lazarus / 31-LCL ---------------------------------------------------------------------- sermo!! · 2011-09-15 08:54 Hi!! I have a form which a main menu which has different options, and if you push one option of the menu the problem does differents things (create new buttons, labels, paintBoxs...) If I want to reset the Form how can I do it??? For example you are in the first option and you realice that you want to do the second option, but the second option is not enabled until you finish the first option, so I would like to reset all the buttons, paintBox, labels, etc. of the first option and have the second option enabled, I think like a "reset a form" or something like that, but I don't know how to do it, because I have tried to do form1.free and then create another one and when I try to close it I can't and the program failed. How could I do it?? Thanks. ---------------------------------------------------------------------- User137 · 2011-09-15 08:57 Would you show in code, where and how you tried to free and create the form? In theory that's one way you can do it. Other is having all default options saved in variables and if you want to cancel it, copy those values over real ones. ---------------------------------------------------------------------- sermo!! · 2011-09-15 15:28 I have put: for i := 0 to ComponentCount - 1 do if Components[i ] is TCheckBox then TCheckBox(Components[ i]).free; and the program failed, however if I put for example: if Components[ i] is TEdit then TEdit(Components[ i]).Text := ''; the program doesn't failed, so I don't know what it's the problem, because I don't want to hide it the checkbox or the labels, I want to erase it ---------------------------------------------------------------------- Shebuka · 2011-09-15 15:48 if you free a component it cease to exist, so it's obvious that if you try to use it after it was destroyed your program fail ---------------------------------------------------------------------- User137 · 2011-09-15 16:04 I was thinking something like: Code: [Select]form1.Free; Application.CreateForm(TForm1, Form1);I didn't test it, maybe this work too: form1:=TForm1.Create(nil); And make sure these are last executed commands in procedure you use. ---------------------------------------------------------------------- sermo!! · 2011-09-15 16:13 Thank you very much "user137", I think the problem was that I put it at the first of the procedure, but now it runs perfectly with this: form1.Free; Application.CreateForm(TForm1, Form1); Thanks again. ---------------------------------------------------------------------- arbelest · 2011-09-16 06:37 Quote from: sermo!! on September 15, 2011, 05:28:31 pmI have put: for i := 0 to ComponentCount - 1 do if Components[i ] is TCheckBox then TCheckBox(Components[ i]).free; and the program failed, however if I put for example: if Components[ i] is TEdit then TEdit(Components[ i]).Text := ''; the program doesn't failed, so I don't know what it's the problem, because I don't want to hide it the checkbox or the labels, I want to erase it I think i know the problem. Code: [Select]  for i := 0 to ComponentCount - 1 do   if Components[i ] is TCheckBox then TCheckBox(Components[ i]).free; That code will produce accessviolation, because you using incremental for looping. Say there is 5 components,  your checkbox at 3' index, so when i --> 3, your checkbox will free AND componentCount also decrease from 5 to 4. Certainly there is nothing at index 4, so looping will fail. Fixed: Code: [Select]  for i := ComponentCount - 1 downto 0 do   if Components[i ] is TCheckBox then TCheckBox(Components[ i]).free;