published property of type variant not streaming correctly when null lazarus / 21-General ---------------------------------------------------------------------- jwharton · 2021-08-25 01:34 I would like to support published properties of type variant.  However, when the value is NULL it doesn't stream into the DFM/LFM correctly.  I have made some changes in the LCL source code and wonder how I can submit these changes to be merged into the source code. This is what I have done in the 2.2.0RC1 r65419: reader.inc 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 function TReader.ReadVariant: variant;var  nv: TValueType;  tmpStr: string;begin  { Ensure that a Variant manager is installed }  if not Assigned(VarClearProc) then    raise EReadError.Create(SErrNoVariantSupport);   FillChar(Result,sizeof(Result),0);   nv:=NextValue;  case nv of    vaIdent:      begin        tmpStr := ReadIdent;        if SameText( tmpStr, 'null' ) then          Result:=system.null        else        if SameText( tmpStr, 'nil' ) then          Result:=system.unassigned      else        if SameText( tmpStr, 'true' ) then          Result:=True        else        if SameText( tmpStr, 'false' ) then        Result:=False        else          raise EReadError.CreateFmt(SUnsupportedPropertyVariantType, [Ord(nv)]);    end;    vaNil:      begin        Result:=system.unassigned;        readvalue;      end;//...  LResources.pp 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 procedure TLRSObjectWriter.WriteVariant(const Value: Variant);begin  case VarType(Value) of    varnull:      WriteIdent('Null');    varsmallint, varinteger, varshortint, varint64, varbyte, varword, varlongword, varqword:      WriteInteger(Value);    varsingle:      WriteSingle(Value);    vardouble:      WriteFloat(Value);    vardate:      WriteDate(Value);    varcurrency:      WriteCurrency(Value);    varolestr, varstring:      WriteString(Value);    varboolean:      WriteBoolean(Value);    else      WriteIdent('Nil');  end;end;  I am not sure how to go about testing this because I haven't yet successfully used the command-line tools to rebuild FPC.  Seems that some of this is beyond the scope of just rebuilding Lazarus. Is there any reason why this is not a good thing to do? Thanks for any input and advice. Regards, Jason Wharton ---------------------------------------------------------------------- ASerge · 2021-08-25 18:09 Quote from: jwharton on August 25, 2021, 03:34:20 amI would like to support published properties of type variant.  However, when the value is NULL it doesn't stream into the DFM/LFM correctly. What does incorrect mean? Example 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 uses Variants; type  TComponentWithVariant = class(TComponent)  private    FIntProp: Integer;    FVarProp: Variant;  published    property VarProp: Variant read FVarProp write FVarProp;    property IntProp: Integer read FIntProp write FIntProp;  end;  procedure TForm1.Button1Click(Sender: TObject);var  C: TComponentWithVariant;  M: TMemoryStream;  R: TReader;  W: TWriter;begin  Memo1.Clear;  RegisterClass(TComponentWithVariant);  M := TMemoryStream.Create;  try    C := TComponentWithVariant.Create(nil);    try      C.VarProp := Null;      C.IntProp := 123;      Memo1.Append(VarToStrDef(C.VarProp, 'Null'));      Memo1.Append(IntToStr(C.IntProp));      W := TWriter.Create(M, 1024);      try        W.WriteRootComponent(C);      finally        W.Free;    end;    finally      C.Free;    end;    M.Position := 0;    R := TReader.Create(M, 1024);    try      C := R.ReadRootComponent(nil) as TComponentWithVariant;      try        Memo1.Append(VarToStrDef(C.VarProp, 'Null'));        Memo1.Append(IntToStr(C.IntProp));      finally        C.Free;      end;    finally      R.Free;    end;  finally    M.Free;  end;end;works correctly. ---------------------------------------------------------------------- jwharton · 2021-08-26 05:32 When I said incorrectly, there was a DFM/LFM entry where it had the name of the property and an equals sign and then nothing after it.  I wouldn't have noticed it except that Lazarus took it as a corrupt and unreadable resource file. ---------------------------------------------------------------------- ASerge · 2021-08-26 11:57 Quote from: jwharton on August 26, 2021, 07:32:28 amWhen I said incorrectly, there was a DFM/LFM entry where it had the name of the property and an equals sign and then nothing after it.  I wouldn't have noticed it except that Lazarus took it as a corrupt and unreadable resource file. OK. In this case, probably only little changes would be enough. Example on Classes.ObjectBinaryToText and Classes.ObjectTextToBinary (the same can be done on LResources.LRSObjectBinaryToText and LResources.LRSObjectTextToBinary): Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i diff --git a/rtl/objpas/classes/classes.inc b/rtl/objpas/classes/classes.incindex e6519cd9b9..49b5350297 100644--- a/rtl/objpas/classes/classes.inc+++ b/rtl/objpas/classes/classes.inc@@ -1895,6 +1895,7 @@ procedure ObjectBinaryToText(Input, Output: TStream; Encoding: TObjectTextEncodi      begin       case ValueType of+        vaNull: OutLn('Null');         vaList: begin             OutStr('(');           IsFirst := True;@@ -2254,6 +2255,8 @@ var             Output.WriteByte(Ord(vaFalse))           else if CompareText(parser.TokenString, 'nil') = 0 then             Output.WriteByte(Ord(vaNil))+          else if CompareText(parser.TokenString, 'Null') = 0 then+            Output.WriteByte(Ord(vaNull))           else           begin           Output.WriteByte(Ord(vaIdent));