Recent

Author Topic: XMLConfig example causes SIGSEGV [BUG]  (Read 9350 times)

Vodnik

  • Full Member
  • ***
  • Posts: 210
XMLConfig example causes SIGSEGV [BUG]
« on: January 10, 2019, 11:28:50 pm »
I just have tried to use TXMLConfig for saving Form size and position, as described in General method here: http://wiki.freepascal.org/Remember_form_position_and_size. Following instructions, I have dropped TXMLConfig to the Form and copy-pasted the two procedures:
Code: Pascal  [Select][+][-]
  1. unit unit_spl;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, XMLConf, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, ExtCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Memo1: TMemo;
  17.     Memo2: TMemo;
  18.     Splitter1: TSplitter;
  19.     XMLConfig1: TXMLConfig;
  20.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  21.     procedure FormShow(Sender: TObject);
  22.     procedure StoreFormState;
  23.     procedure RestoreFormState;
  24.   private
  25.  
  26.   public
  27.  
  28.   end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36. procedure TForm1.StoreFormState;
  37. begin
  38.   with XMLConfig1 do begin
  39.     SetValue('NormalLeft', Left);
  40.     SetValue('NormalTop', Top);
  41.     SetValue('NormalWidth', Width);
  42.     SetValue('NormalHeight', Height);
  43.  
  44.     SetValue('RestoredLeft', RestoredLeft);
  45.     SetValue('RestoredTop', RestoredTop);
  46.     SetValue('RestoredWidth', RestoredWidth);
  47.     SetValue('RestoredHeight', RestoredHeight);
  48.  
  49.     SetValue('WindowState', Integer(WindowState));
  50.   end;
  51. end;
  52.  
  53. procedure TForm1.FormShow(Sender: TObject);
  54. begin
  55.   RestoreFormState;
  56. end;
  57.  
  58. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  59. begin
  60.    StoreFormState;
  61. end;
  62.  
  63. procedure TForm1.RestoreFormState;
  64. var
  65.   LastWindowState: TWindowState;
  66. begin
  67.   with XMLConfig1 do begin
  68.     LastWindowState := TWindowState(GetValue('WindowState', Integer(WindowState)));
  69.  
  70.     if LastWindowState = wsMaximized then begin
  71.       WindowState := wsNormal;
  72.       BoundsRect := Bounds(
  73.         GetValue('RestoredLeft', RestoredLeft),
  74.         GetValue('RestoredTop', RestoredTop),
  75.         GetValue('RestoredWidth', RestoredWidth),
  76.         GetValue('RestoredHeight', RestoredHeight));
  77.       WindowState := wsMaximized;
  78.     end else begin
  79.       WindowState := wsNormal;
  80.       BoundsRect := Bounds(
  81.         GetValue('NormalLeft', Left),
  82.         GetValue('NormalTop', Top),
  83.         GetValue('NormalWidth', Width),
  84.         GetValue('NormalHeight', Height));
  85.     end;
  86.   end;
  87. end;
  88.  
  89. end.
  90.  
When executing, it cause a SIGSEGV exeption when calling XMLConfig1.GetValue procedure, as if XMLConfig1 was not initialized. But why? Did I missed something from the example?
« Last Edit: January 12, 2019, 09:21:06 am by Vodnik »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV
« Reply #1 on: January 10, 2019, 11:46:25 pm »
I assume you have dropped it on the form using OI and you have set the file name?

before reading you should test to see if the file is getting created...

if you have done this then try using "XMLConfig1.flush" to purge it to file after you
write the last one..


Also did you set the ROOTName ?

I also want to make note that you are calling this before a file is even created in the OnShow event...

« Last Edit: January 10, 2019, 11:50:49 pm by jamie »
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV
« Reply #2 on: January 10, 2019, 11:52:39 pm »
Scant as it is, there is some documentation in the wiki beyond that example; see: xmlconf

But if I were you I would use TXMLPropStorage; easier and more useful.
« Last Edit: January 10, 2019, 11:55:17 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: XMLConfig example causes SIGSEGV
« Reply #3 on: January 11, 2019, 12:00:41 am »
I cannot see
Code: Pascal  [Select][+][-]
  1.   XMLConfig1:=TXMLConfig.Create;
anywhere in your example.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV
« Reply #4 on: January 11, 2019, 12:06:45 am »
I cannot see
Code: Pascal  [Select][+][-]
  1.   XMLConfig1:=TXMLConfig.Create;
anywhere in your example.

It's declared in line 19 and, shouldn't it be auto-created with the form? Isn't it a component?

ETA: Yeah, a component in the "System" tab of the palette.
« Last Edit: January 11, 2019, 12:11:18 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: XMLConfig example causes SIGSEGV
« Reply #5 on: January 11, 2019, 12:09:30 am »
Yes, sorry, it is component on the form. I was confused because there are units XMLConf and XMLCfg, both have class TXMLConfig.
« Last Edit: January 11, 2019, 12:13:56 am by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: XMLConfig example causes SIGSEGV
« Reply #6 on: January 11, 2019, 12:18:16 am »
There are some demos in ..lazarus/examples. Demo "xmlstreaming" works with TXMLConfig (from Laz2_XMLCfg), created at runtime.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: XMLConfig example causes SIGSEGV
« Reply #7 on: January 11, 2019, 09:32:02 am »
@jamie,"yes" to all your questions.
Even when onShow event handler is disabled, SIGSEGV appears at  XMLConfig1.SetValue call.
File is not created.

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: XMLConfig example causes SIGSEGV
« Reply #8 on: January 11, 2019, 10:38:16 am »
I have fixed the problem. Issue is with XMLConfig1.Filename property. Being assigned via OI, it appears empty during runtime (other defined in OI properties are OK). So I add string Filename:='config.xml' at the beginning of both procedures StoreFormState and RestoreFormState.
Now example works as expected.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #9 on: January 12, 2019, 12:04:29 am »
You are absolutely correct, it also fails on 1.8.4

 I don't know what release you are using but that is where I am currently installed here.
 
 Are you with the 2.0 CR 3?

 Can someone else verify if this issue exists with Trunk Too?, I did this test on Windersssss 64
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #10 on: January 12, 2019, 12:40:55 am »
Looks like there is a bug in the loading process
Code: Pascal  [Select][+][-]
  1. procedure TXMLConfig.DoSetFilename(const AFilename: String; ForceReload: Boolean);
  2. begin
  3.   if (not ForceReload) and (FFilename = AFilename) then
  4.     exit;
  5.    
  6.   Flush;
  7.   FreeAndNil(Doc);
  8.   if csLoading in ComponentState then
  9.     exit;
  10.   if FileExists(AFilename) and not FStartEmpty then
  11.     LoadFromFile(AFilename)
  12.   else if not Assigned(Doc) then
  13.     begin
  14.     FFileName:=AFileName;
  15.     Doc := TXMLDocument.Create;
  16.     Doc.AppendChild(Doc.CreateElement(FRootName))
  17.     end;
  18. end;                      
  19.  

 it skips out on loading and does not set the name'
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #11 on: January 12, 2019, 12:51:16 am »
it skips out on loading and does not set the name'

I must be dense today but I don't see where it skips out; unless it's when the component is still loading?

ETA: Yeah, of course, while it's loading it should at least set FFileName = AFileName; else the Filename is lost. My head is murky today :-[
« Last Edit: January 12, 2019, 12:56:45 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #12 on: January 12, 2019, 01:05:26 am »
Ok, if this is in the Trunk release maybe someone should report it ?

I find it hard to believe this hasn't been seen before..
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #13 on: January 12, 2019, 01:43:47 am »
It's exactly the same in trunk's xmlconf.pp. No change.

It seems that either nobody has ever used this class or every one who used it did so from code.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #14 on: January 12, 2019, 07:06:08 am »
So I was lucky to be the first who met this bug.
Lazarus 1.8.4, win32.
Should I try to report it to Bugtracker or you guys know better how to proceed with it?

 

TinyPortal © 2005-2018