delphiinline-variable

How to inline static array variables in Rio


I am failing to inline constructs such as

var FileName: array[0..2047] of Char;

This works:

procedure TForm1.AcceptFiles(var Msg: TWMDropFiles);
var FileName: array[0..2047] of Char;
begin
  DragQueryFile(msg.Drop, $FFFFFFFF, FileName, 2048);
  ...
end;

But this fails if FileName is inlined:

procedure TForm1.AcceptFiles(var Msg: TWMDropFiles);
begin
  var FileName: array[0..2047] of Char; // E2029 Expression expected but array found
  DragQueryFile(msg.Drop, $FFFFFFFF, FileName, 2048);
  ...
end;

I managed to inline 12K of variables of any kind, but it seems like anything of the below form can not be inlined:

begin
  var Name: array[X..Y] of Z;
end;

Please advice how it is done in Rio 10.3.3.


Solution

  • As @Remy Lebeau rightfully suggested the solution is to declare the type first

    procedure TForm1.AcceptFiles(var Msg: TWMDropFiles);
    type
      TFileNameArray = array[0..2047] of Char;
    begin
      var FileName: TFileNameArray;
      DragQueryFile(msg.Drop, $FFFFFFFF, FileName, 2048);
      ...
    end;