Delphi 10.3 Rio - Is initializaiton of inline declared record variables needed?

Rad*_*dík 9 delphi delphi-10.3-rio

I am quite excited about Delphi 10.3 Rio inline variable declarations. However I ran into strange problem and it seems that I need to initialize record after it has been inline declared:

program Project8;
{$APPTYPE CONSOLE}
{$R *.res}

uses System.SysUtils,classes;

procedure DoEvil;
  //var sr:TSearchRec; //A
begin
  //var sr:= default(TSearchRec); //B
  var sr:TSearchRec; //C
  sr.Name := EmptyStr; //D
  FindFirst('*.*',faAnyFile,sr);
  while sr.Name<>EmptyStr do
  begin
    Writeln(sr.name);
    sr.Name := EmptyStr;
    FindNext(sr);
  end;
end;

begin
  try
     DoEvil;
    { TODO -oUser -cConsole Main : Insert code here }
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  readln;
end.
Run Code Online (Sandbox Code Playgroud)

The code works fine if I declare sr on line:

  • //A (old style declaration) or on line
  • //B (inline declaration with initialization).

However if I declare sr on line

with exception:

Exception class $C0000005 with message 'access violation at 0x0040ac98: read of address 0xfffffff9'. Process Project8.exe (18928)

I would assume from the address -6, that the string member sr.name is not initialized and is nil.

Just to be complete, Delphi is the new 10.3 release 1: Embarcadero® Delphi 10.3 Version 26.0.33219.4899 - Installed Update 1

Rud*_*uis 6

我在CPU窗口中查看了一下,发现了一些奇怪的地方。

如果我使用旧式的var-block(您的版本// A),则CPU窗口将显示对的调用System._InitializeRecord。一切正常。

如果我将内联声明与Default()(您的版本// B)一起使用,则将本地记录删除,然后使用进行最终确定System._FinalizeRecord,然后再次将其删除。那是很奇怪和无用的,但是可以。

但是,如果我使用的是您的版本// C,则不会执行任何初始化记录的操作:不会退出,不会_InitializeRecord。当我测试您的代码时,事情确实起作用了,但是我可能很幸运。

因此,这显然是一个错误。请报告给Embarcadero质量门户网站


这是在测试默认构造函数,默认析构函数和重载的赋值运算符(但随后将其删除并推迟到下一个版本)时对编译器所做的其余更改。其中一些更改相当死脑筋(例如B版本中的nilling,finalization和nilling),我想其中一些更改已被忘记。

更新资料

显然,这已经报告给了QP: