Advertisement
Guest User

Untitled

a guest
Aug 1st, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.80 KB | None | 0 0
  1. unit UnitDemo;
  2.  
  3. interface
  4.  
  5. uses
  6.   mormot.core.base,
  7.   mormot.core.json,
  8.   mormot.core.rtti;
  9.  
  10. type
  11.   TDetail = class(TSynAutoCreateFields)
  12.   private
  13.     FValue: UTF8String;
  14.   published
  15.     property Value: UTF8String read FValue write FValue;
  16.   end;
  17.  
  18.   TDetailObjArray = array of TDetail;
  19.  
  20.   TComposed = class(TSynAutoCreateFields)
  21.   private
  22.     FValue: TDetail;
  23.     FValueList: TDetailObjArray;
  24.   published
  25.     property Detail: TDetail read FValue write FValue;
  26.     property ValueList: TDetailObjArray read FValueList write FValueList;
  27.   end;
  28.  
  29. procedure CreateAndCopy;
  30.  
  31. implementation
  32.  
  33. procedure CreateAndCopy;
  34. var
  35.   Source, Dest: TComposed;
  36.   Detail: TDetail;
  37. begin
  38.   Source := TComposed.Create;
  39.   Source.Detail.Value := '42';
  40.  
  41.   Detail := TDetail.Create;
  42.   Detail.Value := 'Wuppdi';
  43.   Source.ValueList := Source.ValueList + [Detail];
  44.  
  45.   Dest := TComposed.Create;
  46.  
  47.   // copy all(?) to dest
  48.   CopyObject(Source, Dest);
  49.  
  50.   // change source, expect dest to keep original values
  51.   Source.Detail.Value := 'Life';
  52.   Source.ValueList[0].Value := 'Changed';
  53.  
  54.   Writeln('Source: ', Source.Detail.Value);
  55.   // expect dest to be "42", but it's empty
  56.   Writeln('Dest: ', Dest.Detail.Value);
  57.   // expect different value
  58.   Writeln('Source <> Dest: ', Source.Detail.Value <> Dest.Detail.Value);
  59.   Writeln;
  60.  
  61.   Writeln('Source: ', Source.ValueList[0].Value);
  62.   Writeln('Dest: ', Dest.ValueList[0].Value);
  63.   // would expect different object values, but getting the same
  64.   Writeln('Different Array Objects: ', Source.ValueList[0].Value <> Dest.ValueList[0].Value);
  65.   Writeln;
  66.  
  67.   // Free Source
  68.   Source.Free;
  69.   // Free Dest, creates "Invalid pointer operation", would expect success
  70.   Dest.Free;
  71. end;
  72.  
  73. initialization
  74.   Rtti.RegisterObjArray(TypeInfo(TDetailObjArray), TDetail);
  75.  
  76. end.
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement