Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinyzh/ea75bda48c29eee42af05b3d59ee095f to your computer and use it in GitHub Desktop.
Save edwinyzh/ea75bda48c29eee42af05b3d59ee095f to your computer and use it in GitHub Desktop.
CreateCopy issue with mORMot record with a TRawUTF8List property
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