[Lazarus] Convert record to JSON?

Bo Berglund bo.berglund at gmail.com
Sat Jul 21 13:45:49 CEST 2018


On Sat, 21 Jul 2018 09:29:29 +0200 (CEST), Michael Van Canneyt via
Lazarus <lazarus at lists.lazarus-ide.org> wrote:

>> What have I done wrong?
>
>Because RTTI is made only for published properties.
>
>So, you must make it published properties:
>
>Type
>
>{ needed if you want to descend from TObject.
>   You can also descend from TPersistent. }
>
>{$M+}
>   TMyRecord = Class(TObject)
>   Published
>     Property checksum: word Read FChecksum Write FCheckSum;
>     // etc.
>   end;
>

I changed my definition as above:

  {$M+}
  TEspConfiguration = Class(TObject)  //object
  published
    checksum: word;
    ssid: AnsiString;
    passwd: AnsiString;
    macaddr: AnsiString;
    addr: TIpAddress;
    baud: integer;
    ....
  end;


but then when I compile I get this error (14 times):

wificommhandler.pas(81,5) Error: Symbol cannot be published, can be
only a class

Do I need to declare the fields as private first so they can later be
declared published?

Or are these fields (simple variables and ansistrings) incompatible
with the fpc JSON handling? (Must be a class...)

Maybe it is simpler after all to code this without using fpcjson.
The JSON structure is not that complicated to handle, especially for
writing....


-- 
Bo Berglund
Developer in Sweden



More information about the Lazarus mailing list