Created
July 4, 2020 08:41
-
-
Save zedxxx/41c7ee76a214bd1985878173228100b7 to your computer and use it in GitHub Desktop.
Synopse RecordSave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses | |
SysUtils, | |
SynCommons; | |
{$A8} | |
type | |
TRec = record | |
f1: Word; | |
f2: Byte; | |
f3: UInt64; | |
f4: Byte; | |
f5: Cardinal; | |
f6: Boolean; | |
end; | |
procedure DoTest; | |
var | |
VLen: Integer; | |
VRec: TRec; | |
VRecNew: TRec; | |
VBytes: TBytes; | |
VJson: RawUTF8; | |
begin | |
VLen := SizeOf(TRec); | |
FillChar(VRec, VLen, 88); | |
FillChar(VRecNew, VLen, 88); | |
with VRec do begin | |
f1 := $1234; | |
f2 := $56; | |
f3 := Int64(MaxInt) * 4; | |
f4 := $78; | |
f5 := MaxInt; | |
f6 := False; | |
end; | |
VBytes := RecordSaveBytes(VRec, TypeInfo(TRec)); | |
RecordLoad(VRecNew, PAnsiChar(VBytes), TypeInfo(TRec)); | |
if not CompareMem(@VRec, @VRecNew, VLen) then begin | |
raise Exception.Create('FAIL!'); | |
end; | |
VJson := RecordSaveJson(VRec, TypeInfo(TRec)); | |
Writeln(VJson); | |
VJson := RecordSaveJson(VRecNew, TypeInfo(TRec)); | |
Writeln(VJson); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: