Created
May 13, 2020 11:13
-
-
Save edwinyzh/ea75bda48c29eee42af05b3d59ee095f to your computer and use it in GitHub Desktop.
CreateCopy issue with mORMot record with a TRawUTF8List property
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
program TestTRawUtf8ListCreateCopyErrorPrj; | |
{$APPTYPE CONSOLE} | |
{$R *.res} | |
uses | |
System.SysUtils, | |
SynCommons, | |
mORMot; | |
type | |
// A TSQLRecord-derived class with only one published property of type TRawUTF8List | |
TTestRecord = class(TSQLRecord) | |
private | |
FProp1: TRawUTF8List; | |
public | |
constructor Create; overload; override; | |
destructor Destroy; override; | |
published | |
property Prop1: TRawUTF8List read FProp1 write FProp1; | |
end; | |
constructor TTestRecord.Create; | |
begin | |
inherited Create; | |
FProp1 := TRawUTF8List.Create(); | |
end; | |
destructor TTestRecord.Destroy; | |
begin | |
FreeAndNil(FProp1); | |
inherited Destroy; | |
end; | |
var | |
a, b: TTestRecord; | |
begin | |
try | |
a := TTestRecord.Create; | |
b := a.CreateCopy as TTestRecord; | |
// The following code freeing b will cause EAccessViolation because b was | |
// created by 'CreateCopy'? | |
b.Free; | |
a.Free; | |
except | |
on E: Exception do | |
Writeln(E.ClassName, ': ', E.Message); | |
end; | |
ReadLn; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment