2

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.

Gad D Lord
  • 6,620
  • 12
  • 60
  • 106
  • QC Ticket opened at: https://quality.embarcadero.com/browse/RSP-31970 – Gad D Lord Dec 19 '20 at 02:18
  • Previous inline var tickets already resolved are: https://quality.embarcadero.com/browse/RSP-21925, https://quality.embarcadero.com/browse/RSP-22036, https://quality.embarcadero.com/browse/RSP-22113, https://quality.embarcadero.com/browse/RSP-21680 – Gad D Lord Dec 19 '20 at 02:18
  • 1
    does the problem go away if you define the array type beforehand? `type TFileNameArr = array[0..2048] of Char; var FileName: TFileNameArr;` – Remy Lebeau Dec 19 '20 at 05:33
  • 2
    BTW, you are passing 2048 to the API, but the array has length 2049. – David Heffernan Dec 19 '20 at 08:48
  • @RemyLebeau it works. procedure Proc1; const MAX_FILENAME_LEN = 2048; typeTFileNameArray = array[0..MAX_FILENAME_LEN - 1] of Char; begin var FileName: TFileNameArray; DragQueryFile(Msg.Drop, $FFFFFFFF, FileName, MAX_FILENAME_LEN); Please feel free to submit as answer so I can approve. – Gad D Lord Dec 19 '20 at 10:01
  • 1
    Perhaps inline variable declaration of arrays follows the same rules as [procedural parameters](http://docwiki.embarcadero.com/RADStudio/en/Parameters_(Delphi)#Array_Parameters): *When you declare routines that take array parameters, you cannot include index type specifiers in the parameter declarations.* – LU RD Dec 19 '20 at 11:23

1 Answers1

2

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;
Gad D Lord
  • 6,620
  • 12
  • 60
  • 106