#1 2024-01-09 18:26:08

tbo
Member
Registered: 2015-04-20
Posts: 353

TRttiCustomProps.NameChange - Access violation

Delphi 12 Athens, mORMot2 V2.2

Following test case:

type
  TTestItem = record
    Name1: String;
    Name2: String;
  end;

var
  item: TTestItem;
begin
  item.Name1 := 'A';
  item.Name2 := 'B';
  ShowMessage(Utf8ToString(RecordSaveJson(item, TypeInfo(TTestItem))));

All tests except for the last one are ok. This leads to an access violation:

Rtti.ByTypeInfo[TypeInfo(TTestItem)].Props.NameChange('Name1', '');  // Ok: {"Name2":"B"}
Rtti.ByTypeInfo[TypeInfo(TTestItem)].Props.NameChanges(['Name1'], ['']);  // Ok: {"Name2":"B"} 
Rtti.ByTypeInfo[TypeInfo(TTestItem)].Props.NameChanges(['Name1', 'Name2'], ['N1', 'N2']);  // Ok: {"N1":"A","N2":"B"}
Rtti.ByTypeInfo[TypeInfo(TTestItem)].Props.NameChanges(['Name1', 'Name2'], ['N1', '']);  // Ok: {"N1":"A"}
Rtti.ByTypeInfo[TypeInfo(TTestItem)].Props.NameChanges(['Name1', 'Name2'], ['', 'N2']);  // Error: Access violation

With best regards
Thomas

Last edited by tbo (2024-01-09 18:26:38)

Offline

#2 2024-01-09 21:21:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,686
Website

Re: TRttiCustomProps.NameChange - Access violation

try
https://github.com/synopse/mORMot2/commit/6fe3a481

BTW I guess you should be able to write shorter:

Rtti[TypeInfo(TTestItem)].Props...

Offline

Board footer

Powered by FluxBB