0

Getting access violation errors if I use an inline declared record variable to build a dynamic record array. Does not happen all the time but switching back to a normal declaration for the record variable I haven't seen the error. I wonder if this is a limitation of inline variable declaration or either way I am doing something wrong.

procedure TForm1.FormCreate(Sender: TObject);
Type
  RFruit = record
    FruitName : string;
    FruitBitMask : Int64;
  end;
Var
//AFruitRec : RFruit;
  Fruits : array of string;
  FruitList : array of RFruit;
begin
 Fruits := ['Orange','Apple','Pear','Peach','Grape'];
 Var AFruitRec : RFruit;
 for var i :integer := 0 to length(Fruits) - 1 do
 begin
   AFruitRec.FruitName := Fruits[i];
   AFruitRec.FruitBitMask := Int64(1) SHL i;
   FruitList := FruitList + [AFruitRec];
 end;
end;
Brian
  • 6,717
  • 2
  • 23
  • 31
  • I created a new, empty VCL application, created an empty `FormCreate` event, and copied/pasted your code from `Type` to the `end;` right below `FrultList` directly into that event. I hit F9 to run the app, and got no error or AV. What do I need to do differently to reproduce the issue? – Ken White Feb 16 '19 at 02:39
  • @KenWhite Switch between debug/release, open close the project, restart the IDE - doesn't happen all the time. – Brian Feb 16 '19 at 11:11
  • Doesn't happen for me at all so far. Sounds like you need to figure out how to reproduce the issue (because it *doesn't happen all the time*) and then open a bug report with EMBT once you can provide reproducable steps. – Ken White Feb 17 '19 at 00:19
  • @KenWhite Very odd, reproduced at home with a new install of Delphi 10.3.1 vs work machine with 10.3 and differently setup systems. Thanks for trying. – Brian Feb 17 '19 at 01:44
  • 1
    @Brian It seems there's a problem with record declared inline. https://stackoverflow.com/questions/54987996/delphi-10-3-rio-is-initializaiton-of-inline-declared-record-variables-needed – Ken Bourassa Mar 08 '19 at 21:43

0 Answers0