TWriter.WriteSingle() writes invalid value into *.lfm file lazarus / 31-LCL ---------------------------------------------------------------------- Groffy · 2016-07-14 13:22 Hello, just testing a 3rd party component package with Lazarus trunk / fpc 3.0 and after placing a component onto a form, it writes a property value as Single into the *.lfm file by ending the line with a "s" char. Is that the way to mark the value as data type single? When compiling the application an exception EReadError : Invalid value for property is thrown. With Lazarus 1.6 its working without any problems. Any changes in the TWriter class? With best regards ---------------------------------------------------------------------- korba812 · 2016-07-14 14:06 Hello. There are a few changes to the file lresources.pp: http://bugs.freepascal.org/view.php?id=28040 But should be backward compatible. And is compatible with Delphi. Can you provide a sample? ---------------------------------------------------------------------- Groffy · 2016-07-14 18:33 I will try, but what might be the reason that the TWriter.WriteSingle() writes a "65s" into the *.lfm file? ---------------------------------------------------------------------- korba812 · 2016-07-14 22:39 Your code is correct and You did not have to provide an example. The problem lies in the methods TReader.ReadPropValue and TWriter.WriteProperty and new Lazarus functionality, that allows you to edit and save variant properties.(http://bugs.freepascal.org/view.php?id=30378) Now some float values ar stored in LFM with letter at and. Single values are saved with the 's' at end, currency with 'c' and date with 'd'. Additionally, currency is stored as an integer (currency value * 10000). ---------------------------------------------------------------------- Groffy · 2016-07-15 06:16 Quote from: korba812 on July 15, 2016, 12:39:40 amSingle values are saved with the 's' at end Ok, so the problem seems to be to read back the correct values with the TReader class ---------------------------------------------------------------------- Thaddy · 2016-07-15 06:23 Quote from: korba812 on July 15, 2016, 12:39:40 amNow some float values ar stored in LFM with letter at and. Single values are saved with the 's' at end, currency with 'c' and date with 'd'. Additionally, currency is stored as an integer (currency value * 10000). I have to check, but, really? That is a blatant design mistake. Those kind of info should be stored at negative offsets so the length and content can be considered opaque. It also leads to these kind of problems and questions. This is meta- data. Meta-data describes a.o. what real data to expect. You do that beforehand. That's a bug.... [edit some more] I checked and indeed the info is stored at content end. That makes e.g. parsing difficult because the location of the payload description is not known beforehand and thus extremely inefficient. That - see above - is not correct. Plz revert and do as I described/ suggest. ---------------------------------------------------------------------- korba812 · 2016-07-15 10:34 You're right. It seems that Delphi adds letter at the end only in variant type properties. I'll try fix it. ---------------------------------------------------------------------- Thaddy · 2016-07-15 11:54 Quote from: korba812 on July 15, 2016, 12:34:30 pm only in variant type properties. That is equally evil: Even variants (maybe even specifically variants) should not be stored like that. Variants rely on meta-data complexity, more so than other types. ---------------------------------------------------------------------- korba812 · 2016-07-15 13:04 But in such a manner Delphi stores variant properties (attached example). This is delphi dfm: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object Form1: TForm1  Left = 0  Top = 0  Caption = 'Form1'  ClientHeight = 249  ClientWidth = 418  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  PixelsPerInch = 96  TextHeight = 13  object TestFloatVal1: TTestFloatVal    SingleVal = 123.123001098632800000    DoubleVal = 123.123000000000000000    CurrencyVal = 123.123000000000000000    DateTimeVal = 42370.523171296300000000    VarCurrency = 1231230c    VarDate = 42370.5231712963d    VarSingle = 123.123001098633s    VarDouble = 123.000000000000000000    Left = 40    Top = 32  endend Now I can't reproduce this problem. Seems it works fine (letter is added only to variant properties). Can you test it? ---------------------------------------------------------------------- Thaddy · 2016-07-15 13:15 Delphi engineers can also make basic mistakes. This is a basic mistake. I wonder how that ever got through their quality control. ---------------------------------------------------------------------- korba812 · 2016-07-15 13:34 I do not think it was a mistake. If you look at TUTF8Parser.HandleNumber (lresources.pp), You see that even parser is prepared for that for some time. ---------------------------------------------------------------------- Groffy · 2016-07-16 06:37 However it will be implemented, at least the TReader should be able to read the values which TWriter wrote without throwing an exception. @Thaddy : What is your idea about storing data type Variant, how to store the data type information? ---------------------------------------------------------------------- Thaddy · 2016-07-16 08:26 You store meta-data that describes what to expect before you store actual data. The reason for that is that from the description in the meta-data you can choose the most efficient way to process the actual data. So store a description first, then store the payload. If you store meta-data at the end of the actual data you can not apply such a pattern. You will have to read out all data and after that decide how to compute. That is not a very smart way to compute That is a pretty generic design pattern or even design principle: Store meta-data before the actual data itself. ---------------------------------------------------------------------- Thaddy · 2016-07-16 09:22 Quote from: korba812 on July 15, 2016, 03:34:50 pmI do not think it was a mistake. If you look at TUTF8Parser.HandleNumber (lresources.pp), You see that even parser is prepared for that for some time. I beg to differ because of the explanation I gave above. That something is already implemented in a certain way does not give any indication if it is implemented in the right way. Which it isn't... I am merely explaining theory. That is also language independent. E.g. I want to know if I am dealing with a telephone number (which I can't do much math with and can sub-sequentially be ignored) or a read out from some sensor.... Such a decision is based on meta-data info. See the point? ---------------------------------------------------------------------- korba812 · 2016-07-16 12:36 I understand that. But this applies to binary data without a defined format (as in the case of streaming binary objects for example via Treader / TWriter) when you should first read the type of data and then the data. LFM / DFM has a structure - one value per line, so if you want to read the value correctly, you need to process the entire line. Another thing is that the values are saved in decimal, so still you must first read the whole line to correctly convert to binary format.