Author Topic: [solved] form reset/reload  (Read 380 times)

ADMGNS

  • Jr. Member
  • **
  • Posts: 83
  • keep it simple and smart
[solved] form reset/reload
« on: August 05, 2026, 11:57:31 pm »
hello,

is there a simple way to reset/reload a form returning to initial values without extra savings etc?

ie, like

formSettings.Reload(sender);

thnx
« Last Edit: August 08, 2026, 09:59:18 pm by ADMGNS »

Aruna

  • Hero Member
  • *****
  • Posts: 821
Re: form reset/reload
« Reply #1 on: August 06, 2026, 02:30:48 am »
hello,

is there a simple way to reset/reload a form returning to initial values without extra savings etc?

ie, like

formSettings.Reload(sender);

thnx
Uncompress and run the source in the attched zip file. Change everything and anything you want (Screenshot attached) then click the reset button. Please go through the source code and if you have questions do ask. Hope this helps.

ADMGNS

  • Jr. Member
  • **
  • Posts: 83
  • keep it simple and smart
Re: form reset/reload
« Reply #2 on: August 06, 2026, 02:49:23 am »
@aruna

tenx for your reply, but, i know this type resetting.

actually, i am asking for a kind of "factory" reset..

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.FormDblClick(Sender: TObject);
  2. begin
  3.   if Assigned(frmMain) then frmMain.Free;
  4.   //if Assigned(frmMain) then frmMain.FreeInstance;
  5.   if Assigned(frmMain) then frmMain := Nil;
  6.  
  7.   Application.Initialize;
  8.   Application.CreateForm(TfrmMain, frmMain);
  9.   Application.Run;
  10. end;    
  11.  


i've tried this above code experimentally but when closeing the form/app, it raises a system wide error..

tenx

ADMGNS

  • Jr. Member
  • **
  • Posts: 83
  • keep it simple and smart
Re: form reset/reload
« Reply #3 on: August 06, 2026, 03:04:03 am »
sorry, in hurry, i've forgotten some things..

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  2. begin
  3.   CanClose := False;
  4.   Halt;
  5. end;  
  6.  

it seems this can solve the problem, but, it's not thing i'm looking for.. anyway

tenx

Aruna

  • Hero Member
  • *****
  • Posts: 821
Re: form reset/reload
« Reply #4 on: August 06, 2026, 03:08:36 am »
sorry, in hurry, i've forgotten some things..

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  2. begin
  3.   CanClose := False;
  4.   Halt;
  5. end;  
  6.  
[

tenx
Try this one.  This works but I take no responsibility if anything brakes :) Good Luck! I would wait for more experienced folks to weigh in on this if your going to use this in production code.

« Last Edit: August 06, 2026, 03:10:10 am by Aruna »

ADMGNS

  • Jr. Member
  • **
  • Posts: 83
  • keep it simple and smart
Re: form reset/reload
« Reply #5 on: August 06, 2026, 03:16:00 am »
hello again,

yes, it is.. it looks like good solution.

Quote
This works but I take no responsibility if anything brakes :)

OK, agreee..

tenx

Aruna

  • Hero Member
  • *****
  • Posts: 821
Re: form reset/reload
« Reply #6 on: August 06, 2026, 03:23:14 am »
hello again,

yes, it is.. it looks like good solution.
My friend looks can be deceiving :)

Quote
This works but I take no responsibility if anything brakes :)

OK, agreee..

tenx
I would really wait for senior people like Martin_fb, wp,Thaddy, Pascal Dragon,  marcov, MarkMLI and all the other far more battle tested veterans for their comments. Yes it works but I prefer to get a solid concrete 'Alright, use this ..' from the folks I mentioned. Or test it thoroughly and try to break it?  cdbc aka benny your needed friend so is dsiders :) Davo what do ya think?
« Last Edit: August 06, 2026, 03:25:13 am by Aruna »

ADMGNS

  • Jr. Member
  • **
  • Posts: 83
  • keep it simple and smart
Re: form reset/reload
« Reply #7 on: August 06, 2026, 03:37:58 am »
tested and approved by ADMGNS. no needs anymore :)

dsiders

  • Hero Member
  • *****
  • Posts: 1679
Re: form reset/reload
« Reply #8 on: August 06, 2026, 03:43:57 am »
hello,

is there a simple way to reset/reload a form returning to initial values without extra savings etc?

ie, like

formSettings.Reload(sender);

thnx
Uncompress and run the source in the attched zip file. Change everything and anything you want (Screenshot attached) then click the reset button. Please go through the source code and if you have questions do ask. Hope this helps.

And using the customforms package in components/customforms, you can register the new form type so it appears on the File > New dialog.

But in short, the "factory reset" is not built in to TForm.

ADMGNS

  • Jr. Member
  • **
  • Posts: 83
  • keep it simple and smart
Re: [solved] form reset/reload
« Reply #9 on: August 08, 2026, 09:58:42 pm »
by getting some help from AI (gemini)..

Code: Pascal  [Select][+][-]
  1. unit uFormResetter;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls;
  9.  
  10. procedure GlobalFactoryReset(aForm: TCustomForm);
  11.  
  12. implementation
  13.  
  14. type
  15.   TResetWorker = class
  16.   private
  17.     FFormClass: TCustomFormClass;
  18.     FFormVarPointer: ^TCustomForm;
  19.     procedure ExecuteReset(Data: PtrInt);
  20.   public
  21.     constructor Create(aForm: TCustomForm);
  22.   end;
  23.  
  24. constructor TResetWorker.Create(aForm: TCustomForm);
  25. begin
  26.   inherited Create;
  27.   FFormClass := TCustomFormClass(aForm.ClassType);
  28.   FFormVarPointer := Pointer(InterlockedCompareExchangePointer(Pointer(aForm), nil, nil));
  29. end;
  30.  
  31. procedure TResetWorker.ExecuteReset(Data: PtrInt);
  32. var
  33.   newBurn: TCustomForm;
  34. begin
  35.   TCustomForm(Data).Release;
  36.   newBurn := FFormClass.Create(Application);
  37.   newBurn.Show;
  38.   Self.Free;
  39. end;
  40.  
  41. procedure GlobalFactoryReset(aForm: TCustomForm);
  42. var
  43.   Worker: TResetWorker;
  44. begin
  45.   if not Assigned(aForm) then Exit;
  46.   Worker := TResetWorker.Create(aForm);
  47.   Application.QueueAsyncCall(@Worker.ExecuteReset, PtrInt(aForm));
  48. end;
  49.  
  50. end.
  51.  

and it's usage is, in any form:

Code: Pascal  [Select][+][-]
  1. GlobalFactoryReset(Self)

regs

 

TinyPortal © 2005-2018