[Lazarus] Convert record to JSON?

Bo Berglund bo.berglund at gmail.com
Sun Jul 22 00:22:58 CEST 2018

On Sat, 21 Jul 2018 17:47:54 +0200, Sven Barth via Lazarus
<lazarus at lists.lazarus-ide.org> wrote:

>Look at the code that Michael wrote. He used properties on purpose, 
>because only *properties* can be published while not being a class type.

Sorry, did not fully note the property keyword!
Not doing that made it easier to support both object and record
through conditional defines without changing the body of the code...

But it now means I have to use a new structure like this:

TIpAddress = array[0..3] of byte;

TEspConfiguration = Class(TObject)
  Fchecksum: word;
  Fssid: AnsiString;
  Fpasswd: AnsiString;
  Fmacaddr: AnsiString;
  Fhost: AnsiString;
  Faddr: TIpAddress;
  Fbaud: integer;
  Ftcpport: word;
  Fmode: byte;
  Fchannel: byte;
  Fhidden: byte;
  Ffixedaddress: byte;
  Fnumsensors: byte;
  Fdhtinterval: word;
  property checksum: word read Fchecksum write Fchecksum;
  property ssid: AnsiString read Fssid write Fssid ;
  property passwd: AnsiString read Fpasswd write Fpasswd;
  property macaddr: AnsiString read Fmacaddr write Fmacaddr;
  property host: AnsiString read Fhost write Fhost;
  property addr: TIpAddress read Faddr write Faddr;
  property baud: integer read Fbaud write Fbaud;
  property tcpport: word read Ftcpport write Ftcpport;
  property mode: byte read Fmode write Fmode;
  property channel: byte read Fchannel write Fchannel;
  property hidden: byte read Fhidden write Fhidden;
  property fixedaddress: byte read Ffixedaddress write Ffixedaddress;
  property numsensors: byte read Fnumsensors write Fnumsensors;
  property dhtinterval: word read Fdhtinterval write Fdhtinterval;

Can the JSON handlers deal with the array type TIpAddress?

And how do I "plug" the fpjson.helper.pp code into my project?

Bo Berglund
Developer in Sweden

More information about the Lazarus mailing list