Recent

Author Topic: [solved] "not initialized" (array set length to zero)  (Read 361 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
[solved] "not initialized" (array set length to zero)
« on: November 28, 2022, 07:25:24 pm »
Here I read interesting discussions about the "not initialized" warning, which I understood partly.
I know, this code lines do not makes sense. They are a simplification of my code.

This is a situation in my code:

  Anzahl:=0;
  SetLength(result, Anzahl);

where these lines are part of a function, of which the result is an
 array of....(some type)

Can somebody kindly comment what I shall do best to get rid of the warning?
it reads
Warning: function result variable of a managed type does not seem to be initialized.




« Last Edit: November 29, 2022, 12:59:04 pm by Nicole »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: "not initialized" (array set length to zero)
« Reply #1 on: November 28, 2022, 07:40:08 pm »

This could be a problem with the compiler not able to decide if that is or is not actually initiated.

 The SetLength is taking that as a parameter and the compiler thinks it is just a input when in fact it is conditioning the Array.

 Have you tried Result := []; ?


The only true wisdom is knowing you know nothing

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: "not initialized" (array set length to zero)
« Reply #2 on: November 28, 2022, 07:45:00 pm »
Or try
Code: Pascal  [Select][+][-]
  1. Anzahl:=0;
  2. result:=nil; // <- Adding this line remove the warning
  3. SetLength(result, Anzahl);
« Last Edit: November 28, 2022, 08:56:17 pm by Lulu »
wishing you a nice life

 

TinyPortal © 2005-2018