Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitDemo;
- interface
- uses
- mormot.core.base,
- mormot.core.json,
- mormot.core.rtti;
- type
- TDetail = class(TSynAutoCreateFields)
- private
- FValue: UTF8String;
- published
- property Value: UTF8String read FValue write FValue;
- end;
- TDetailObjArray = array of TDetail;
- TComposed = class(TSynAutoCreateFields)
- private
- FValue: TDetail;
- FValueList: TDetailObjArray;
- published
- property Detail: TDetail read FValue write FValue;
- property ValueList: TDetailObjArray read FValueList write FValueList;
- end;
- procedure CreateAndCopy;
- implementation
- procedure CreateAndCopy;
- var
- Source, Dest: TComposed;
- Detail: TDetail;
- begin
- Source := TComposed.Create;
- Source.Detail.Value := '42';
- Detail := TDetail.Create;
- Detail.Value := 'Wuppdi';
- Source.ValueList := Source.ValueList + [Detail];
- Dest := TComposed.Create;
- // copy all(?) to dest
- CopyObject(Source, Dest);
- // change source, expect dest to keep original values
- Source.Detail.Value := 'Life';
- Source.ValueList[0].Value := 'Changed';
- Writeln('Source: ', Source.Detail.Value);
- // expect dest to be "42", but it's empty
- Writeln('Dest: ', Dest.Detail.Value);
- // expect different value
- Writeln('Source <> Dest: ', Source.Detail.Value <> Dest.Detail.Value);
- Writeln;
- Writeln('Source: ', Source.ValueList[0].Value);
- Writeln('Dest: ', Dest.ValueList[0].Value);
- // would expect different object values, but getting the same
- Writeln('Different Array Objects: ', Source.ValueList[0].Value <> Dest.ValueList[0].Value);
- Writeln;
- // Free Source
- Source.Free;
- // Free Dest, creates "Invalid pointer operation", would expect success
- Dest.Free;
- end;
- initialization
- Rtti.RegisterObjArray(TypeInfo(TDetailObjArray), TDetail);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement