Recent

Author Topic: TStringList & TStringArray(Solved)  (Read 220 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1259
TStringList & TStringArray(Solved)
« on: November 19, 2022, 05:58:54 pm »
  I get an error on freeing the ItemArray but I have to create it. Seems wrong.

Code: Pascal  [Select][+][-]
  1. Var
  2.   LList: TStringList;
  3.   ItemArray: TStringArray;
  4.  begin
  5.   LLIst:= TStringList.Create;
  6.   ItemArray:=TStringArray.Create;
  7. ...
  8.    finally
  9.     if Assigned(LList) then
  10.                FreeAndNil(LList);        
  11.     if Assigned(ItemArray) then
  12.                FreeAndNil(ItemArray);  <== Error
  13.      
 
   
« Last Edit: November 19, 2022, 06:27:17 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Thaddy

  • Hero Member
  • *****
  • Posts: 12543
Re: TStringList & TStringArray
« Reply #1 on: November 19, 2022, 06:01:58 pm »
Since ItemArray is a dynamic array, you do not call free, let alone the evil freeandnil, but setlength(ItemArray,0);
An array is not a class. There is a "constructor" but never a destructor.
« Last Edit: November 19, 2022, 06:07:45 pm by Thaddy »
Writing code in an overly complex way is usually merely a complete misunderstanding of the goal you are trying to achieve.

JLWest

  • Hero Member
  • *****
  • Posts: 1259
Re: TStringList & TStringArray
« Reply #2 on: November 19, 2022, 06:26:56 pm »
Ok- Corrected
Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018