Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program PropertyField_02dField_01;
- {$APPTYPE CONSOLE}
- uses
- mormot.core.json,
- mormot.core.rtti,
- mormot.orm.core;
- type
- TSource = class(TSynAutoCreateFields)
- private
- FField_01: UTF8String;
- FField_02: UTF8String;
- published
- property Field_01: UTF8String read FField_01 write FField_01;
- // even though unused in sample, the prop is needed to force error
- property Field_02: UTF8String read FField_02 write FField_02;
- end;
- TDestination = class(TOrm)
- private
- FDestProp: UTF8String;
- published
- property DestProp: UTF8String read FDestProp write FDestProp;
- end;
- var
- Source: TSource;
- Dest: TDestination;
- SourceRtti, DestRtti: TRttiCustom;
- SourceProp, DestProp: PRttiCustomProp;
- CopyData: TRttiVarData;
- begin
- // register classes
- DestRtti := Rtti.RegisterClass(TSource);
- SourceRtti := Rtti.RegisterClass(TDestination);
- // get source and dest props
- SourceProp := DestRtti.Props.Find('Field_01');
- DestProp := SourceRtti.Props.Find('DestProp');
- // check them
- Writeln('PropSource ', SourceProp^.Name);
- Writeln('PropDest ', DestProp^.Name);
- // create source
- Source := TSource.Create;
- try
- // and prepare
- // Note: If you put something into Field_01, everything works as expected
- // it seems to be the empty string, that causes the trouble
- Source.Field_01 := '';
- Source.Field_02 := '';
- // create dest
- Dest := TDestination.Create;
- try
- // read source value
- SourceProp^.GetValue(Source, CopyData);
- Writeln(CopyData.VType);
- // CopyData.VType will be 256/0x0100 for empty string
- // CopyData.VType will be 16640/0x4100 for non-empty string
- // write to dest - EXCEPTION on empty string value
- // Note: I have tried both for "andclear", true and false
- // without seeing a difference
- DestProp^.SetValue(Dest, CopyData, False);
- // write content of dest
- Writeln('Destination.DestProp _', Dest.DestProp, '_');
- finally
- Dest.Free;
- end;
- finally
- Source.Free;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment