Recent

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

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #15 on: January 12, 2019, 09:19:39 am »
Bug report 0034854

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV [BUG]
« Reply #16 on: January 12, 2019, 02:27:30 pm »
Yes you are one LUCKY dude!  :D

Better buy your LOTTO tickets now!
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV [FIXED]
« Reply #17 on: January 12, 2019, 03:34:52 pm »
So I was lucky to be the first who met this bug.

Probably not, but it looks like any others who did find it were silent. It's the Microsoft way: find a bug, work around it and never tell a soul about it.  :D
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 [BUG]
« Reply #18 on: January 12, 2019, 03:59:09 pm »
Quote
Probably not, but it looks like any others who did find it were silent. It's the Microsoft way: find a bug, work around it and never tell a soul about it.  :D

Maybe. However, I never used TXMLConfig from FCL. I always use Laz2_DOM and Laz2_XML... alternatives, they play better with Lazarus because of UTF8.
http://wiki.freepascal.org/XML_Tutorial
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 [BUG]
« Reply #19 on: January 12, 2019, 06:24:42 pm »
Blaazen, thank you for the info! I start using TXMLConfig just because I have come across a ready made example of how to save/restore form size.  Laz2_DOM and Laz2_XML... looks more powerful and file format is nicer.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV [BUG]
« Reply #20 on: January 12, 2019, 07:18:05 pm »
You should really investigate TXMLPropStorage: it can save/reload automatically almost any property you care about and it also allows saving/restoring other configuration values. I use it in almost all my applications and it works like a charm.

Although slightly, the page you cited, Remember form position and size, talks about it too.
« Last Edit: January 12, 2019, 07:24:40 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.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV [BUG]
« Reply #21 on: January 12, 2019, 07:38:12 pm »
Yes I agree 100%, currently where you are at it does exactly what you want.

Not only that, it looks like you can also insert additional items using the same instance supplying
different sections not related to the FORM for example..

--
 More digging, I find that not only does it have this problem but it also calls the Flush and FreeAndNil on a
DOC object that has not yet been created or the DOC variable initialize to Nil..

 I am assuming the heap space for each instance of a Class does not auto-clear the memory to 0 ?

 If this is the case then I can see this component and any one that inherits from it generating a random
Segfault or maybe just corrupting other parts of code..

 In the constructor the inherited constructor is called which is Tcomponent, that takes care of reading the
Properties from file and assigning them. So the DoSetFIleName method gets called during this process and
a Flush, FreeAndNil(DOC) is done, However, the DOC member does not get set until the top constructor completes
, even the overridden method LOADED gets called which also then Sets the filename will hit the same wall
before the Top level constructor completes which is where the actual DOC is initially created.

Code: Pascal  [Select][+][-]
  1. constructor TXMLConfig.Create(AOwner: TComponent);
  2. begin
  3.   inherited Create(AOwner); // This will call the DoSetFileName method for the filename string.
  4.   FRootName := 'CONFIG'; // This looks like it is overriding the property in the OI
  5.   Doc := TXMLDocument.Create;
  6.   Doc.AppendChild(Doc.CreateElement(FRootName));
  7. end;                              
  8.  

Maybe I don't understand the loading procedures of a component with published properties in Lazarus, I know
that is how they work in Delphi as I layout.

 The Constructor in TComponent will do all the fancy stuff to assign the properties

 Maybe the Inherited Create should be called at the end instead ?

Did I over look something here?

Nope: Scratch that last one, I forgot the ReadState is called well after..
« Last Edit: January 13, 2019, 02:16:55 am by jamie »
The only true wisdom is knowing you know nothing

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: XMLConfig example causes SIGSEGV [BUG]
« Reply #22 on: January 13, 2019, 09:04:48 pm »
lucamar, I have tried TXMLPropStorage.
I would definitely use it if not for one nuance: it set the properties at program startup only. In my application I want some control settings to be set depending upon which DB will user open. E.g. list of checkboxes is loaded from DB (list of sites), I would like those of them to be checked, that were checked last time this DB was opened. So I'm planning to store DB name as a section/level and list of controls settings, specific for it in XML file. Maybe not very nice idea from the programming point of view, but convenient for users. Anticipating logical suggestion to store settings in DB itself, I will say that it is not allowed to write or change anything in it.
So, using TXMLPropStorage to store form size, splitter position, etc. and XMLConfig for other controls I don't want. Just one component for all purposes.
« Last Edit: January 13, 2019, 09:10:40 pm by Vodnik »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: XMLConfig example causes SIGSEGV [BUG]
« Reply #23 on: January 13, 2019, 09:38:22 pm »
You are not restricted to the form or control settings..

you can also set StoredValues and Read them using the OnSaveSaving and OnRestoring events that do not
otherwise get taken care of..

go to the items and click on it, you can add storedValues..

These values must be set during saving and Loading using the events, so if gives you a chance to put in
custom values.

 Also you think you can force an update early
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: XMLConfig example causes SIGSEGV [BUG]
« Reply #24 on: January 13, 2019, 09:48:10 pm »
lucamar, I have tried TXMLPropStorage.
I would definitely use it if not for one nuance: it set the properties at program startup only. In my application I want some control settings to be set depending upon which DB will user open. E.g. list of checkboxes is loaded from DB (list of sites), I would like those of them to be checked, that were checked last time this DB was opened. So I'm planning to store DB name as a section/level and list of controls settings, specific for it in XML file. Maybe not very nice idea from the programming point of view, but convenient for users. Anticipating logical suggestion to store settings in DB itself, I will say that it is not allowed to write or change anything in it.
So, using TXMLPropStorage to store form size, splitter position, etc. and XMLConfig for other controls I don't want. Just one component for all purposes.

Huh? XMLPropStorage has methods to save or load the configuration at any time, not just on start. Moreover, you can use it to store/retrieve any value you want, not just published properties, under however many levels you want. In fact TXMLPropStorage uses XMLConfig at bottom so almost anything that can be done with XMLConfig can also be done with TXMLPropStorage.

But each to its own, I guess; whatever you're comfortable with. :)
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.

 

TinyPortal © 2005-2018