Lazarus

Programming => General => Topic started by: matthius on May 16, 2021, 01:43:41 pm

Title: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: matthius on May 16, 2021, 01:43:41 pm
Hello !

I want to create a LFM file from a registered form TF_FormDico.

But there is a SIGSEGV error on Writer.WriteDescendenton calling CreateLFMFile.

What can i do ?
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: speter on May 16, 2021, 02:24:53 pm
What can you do?

Easy, provide some code! :)

cheers
S.
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: matthius on May 16, 2021, 02:46:39 pm
Here it is :

Code: Pascal  [Select][+][-]
  1. function fb_CreateForms ( var amif_Init : TIniFile; const as_destination : String ) : Boolean;
  2. var li_i : Integer;
  3.     LFileLFM : TFileStream;
  4.     aform : TF_XMLForm;
  5.     aformdico : TF_Formdico;
  6. Begin
  7.   FreeAndNil(gxdo_FichierXML);
  8.   if fb_CreateProject ( amif_Init, Application )
  9.   and fb_LoadXMLFile ( gxdo_FichierXML, fs_getLeonDir + gs_ProjectFile ) Then
  10.     Begin
  11.       Result := True;
  12.       // La fenêtre n'est peut-être pas encore complètement créée
  13.       gchar_DecimalSeparator := ',' ;
  14.       DecimalSeparator := gchar_DecimalSeparator ;
  15.       for li_i:=0 to High(ga_Functions) do
  16.        with ga_Functions [ li_i ] do
  17.         Begin
  18.          aform:=fxf_ExecuteAFonction ( li_i, true        );
  19.          aformdico := TF_FormDico.Create(Application);
  20.          aform.p_exchangeSources(aformdico);
  21.          if Assigned(aform)
  22.           Then
  23.            try
  24.              LFileLFM := TFileStream.Create(as_destination+Clep+'.lfm',fmCreate);
  25.              CreateLFMFile(aformdico,LFileLFM);
  26.            finally
  27.             LFileLFM.Destroy;
  28.             aform.Destroy;
  29.             aformdico.Destroy;
  30.            end;
  31.         end;
  32.     End
  33.    Else
  34.     Result := False;  
  35. end;  

The source is here :
https://sourceforge.net/p/xml-frames-vrad-lazarus/code/ci/default/tree/XMLToLFM/u_createproject.pas
https://sourceforge.net/p/xml-frames-vrad-lazarus/code/ci/8a78bcb3267b78a2a4b71e99bcb129c9505b3345/tree/demos/weo_firebird/builder.lpi
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: matthius on May 17, 2021, 11:26:40 am
I want to create a lfm file with every porperties saved. I do not want to select some properties because there are a lot to save.

What is the method which save properties on TApplicationProperties ?
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: lucamar on May 17, 2021, 12:46:15 pm
TApplicationProperties is not meant to save/load properties; for that one should rather use the form's SessionProperties along with any of the TFormPropertyStorage descendants (TIniPropStorage, TXMLPropStorage, etc.), which have convenient events which are called before/after saving/restoring and allow you to store any additional value you might want.

An example, from one of my own apps, which loads a Memo after reading the file name from a TXMLPropStorage instance on application restart:
Code: Pascal  [Select][+][-]
  1. procedure TMain.RestoreProperties(Sender: TObject);
  2. begin
  3.   CurrentFile := XMLStore.ReadString('File', '');
  4.   if CurrentFile = FDefaultFile then
  5.     CurrentFile := '';
  6.   if (CurrentFile <> '') and FileExists(CurrentFile) then
  7.     Memo.ReadFromFile(CurrentFile)
  8.   else if FileExists(FDefaultFile) then begin
  9.     Memo.ReadFromFile(FDefaultFile);
  10.     Memo.Filename := '';
  11.   end;
  12.   Timer.Enabled := itOptionsTimer.Checked;
  13. end;
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: matthius on May 17, 2021, 01:52:12 pm
But i want to create a LFM file.

Lazarus uses Writer.WriteDescendent in CustomFormEditor.

Why does it work ?
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: Martin_fr on May 17, 2021, 02:15:50 pm
Maybe it is something in your data? (inheritance of TF_XMLForm? inheritance of other classes used within? dangling pointer? ....)

Can you provide a "cut down" simple project, that we can open in our IDE and run, and that will have the crash?


I understand you want an lfm.
And even if you changed your mind, it might be helpful to first understand what went wrong. So following this up should stay on the table.

But I thought I might yet point you to an alternative, that may be of interest.
   TRttiXMLConfig  in unit Laz2_XMLCfg

This will write published properties to an xml file. (It is what the IDE uses for it's own config).
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: matthius on May 17, 2021, 02:56:37 pm
It crashes on a form registered with RegisterCustomForm.

I will do with it.
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: Martin_fr on May 17, 2021, 03:30:07 pm
You mean RegisterCustomForm in unit WSForms?
That is odd. That is not Streaming related.

Is your project a GUI application?

If you use the class TForm (or TCustomForm) then you need to include the unit Interfaces (as will happen for any GUI app, but not for "simple program".)
If you do not need to display the form, there is a "nogui" widgetset, that can be chosen in "project options"

Though, not using interfaces would get a compile time error (afaik). So a crash means something else....
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: matthius on May 18, 2021, 05:09:49 pm
I cannot register my form. But i want.
Title: Re: Writer.WriteDescendent SIGSEGV error on calling CreateLFMFile
Post by: Martin_fr on May 18, 2021, 05:41:44 pm
I cannot register my form. But i want.
What are you trying to do?

RegisterCustomForm in unit WSForms does not register a/your custom form.

It does register TCustomForm (which is the base class of all forms). And this is done once by the LCL.
It basically links the LCL class to the win32/gtk/cocoa/.... specific code in the backend.


Maybe you were looking for something like RegisterClass(es) or RegisterComponents?
Those are streaming related.
TinyPortal © 2005-2018