* * *

Author Topic: TForm.ProcessResource  (Read 1170 times)


  • Guest
« on: September 03, 2017, 03:45:25 pm »
does anyone had to reload default controls values and properties at runtime, for a form to display reintitialized, with its embeded lfm resource?

until today I was making a procedure setting checkboxes, Edits, Radiobuttons (and so on) to what values I gave at design time if a 'reset to default' button/action was executed.

I saw yesterday that TForm has a method named 'ProcessResource' which loads the defaults values after the widget's creation. So I made something like this :

Code: Pascal  [Select]
  1. procedure TMForm.RstActionExecute(Sender: TObject);
  2. begin
  3.   Visible:=false;
  4.   MainMenu.Free;
  5.   repeat
  6.     Components[Pred(ComponentCount)].Free; // clean form, destroy childs
  7.   until ComponentCount = 0;
  8.   Application.ProcessMessages; // sync tthe deletions with widgetset
  9.   ProcessResource; // load lfm res, recreate internally children with designtime values
  10.   CreateWnd; // widgetset recreate Form
  11.   Visible:=true;
  12. end;

and I debuged the whole thing ensuring there was no error.
all went fine until tne final 'end';
then I ran to continue the program but a wonderful SIGSEGV poped

should I continue to use a self made reset procedure assigning default values and properties, or is there a way to reload them nicely from the embeded lfm resource, with no SIGSEGV?

by advance, thank you
« Last Edit: September 03, 2017, 08:02:08 pm by sam707 »


  • Hero Member
  • *****
  • Posts: 712
Re: TForm.ProcessResource
« Reply #1 on: September 03, 2017, 04:17:22 pm »
Have you considered not recreating the window ?


  • Guest
Re: TForm.ProcessResource
« Reply #2 on: September 03, 2017, 05:52:56 pm »
recreating completely the main form assumes to destroy it, if so, application then will terminate, thats problem. I need a reread the original state from resource, Form should not be totally destroyed, even more if it is the MAIN form ==> end of program

createWnd being commented out I have the same result. I call it because it resets the Form caption
« Last Edit: September 03, 2017, 08:07:00 pm by sam707 »


  • Hero Member
  • *****
  • Posts: 2669
Re: TForm.ProcessResource
« Reply #3 on: September 03, 2017, 08:35:10 pm »
You have to do this the hard way, iterating each property you want to be reset.
See the attached project for an idea.
Implementation of Assign is rather hit-and-miss for most controls, so there is no generalised way of reliably cloning arbitrary properties that I am aware of.


  • Guest
Re: TForm.ProcessResource
« Reply #4 on: September 03, 2017, 10:07:05 pm »
wow thanks @howardpc, that's a clever idea!

==> create a new form from the class, and copy back values and properties.

I was expecting Lazarus 'TForm.Processresource' method to inplace reinit/reread the form's components... but ok, your temporary form solution seems a good one. Unfortunately, it consumes much more memory and resources than my (I thought) 'obsolete' way to call a procedure that set values and properties progammatically.

SO, i"am adding to my lazarus wishlist => a method to reload default components/contros values/props, in the state as they were at designtime.
« Last Edit: September 03, 2017, 10:09:29 pm by sam707 »



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus