Recent

Author Topic: Solved - Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2  (Read 3027 times)

Wilko500

  • Full Member
  • ***
  • Posts: 180
After upgrading Lazarus/FPC to the latest stable release my program which was compiling and running without error is now erroring with Illegal Qualifier. I was unable to find any changes to TStringArray in the release notes so I am puzzled.  Might someone be able to help?
The line in question is tmpList.Create;
Code: Pascal  [Select][+][-]
  1. Constructor TChartDetails.Create(ChId2: String);
  2. Var
  3.    INI:         TIniFile;
  4.    AppPath:     String;
  5.    ChList:      String;
  6.    tmpList:     TstringArray;
  7. Begin
  8. //Chart Description
  9. //Lookup chart details for supplied ChartId from INI file
  10. //Not good practice as not always platform independant, notably on Mac, may not return correct path
  11. AppPath:=ExtractFileDir(Paramstr(0)); //Get application path
  12. INI:=TIniFile.Create(AppPath + '\' + 'FlowChart.ini');
  13. ChList:= INI.ReadString('Charts',ChId2,'');
  14. tmpList.Create;
  15. tmpList:=ChList.Split(['|'],TStringSplitOptions.ExcludeEmpty); //Exclude last (enpty value)
  16. ChartId:=ChId2;
  17. ChartFileName:=tmpList[1];
  18. ChartGroup:=tmpList[2];
  19. ChartTitle:=tmpList[3];
  20. ChDateCreated:=tmpList[4];
  21. ChDa]"]>Blockeddified:=tmpList[5];
  22. End;
  23.  
« Last Edit: April 08, 2022, 11:51:08 pm by Wilko500 »
MacBook Pro mid 2015 with OS Monterey 12.7.6
FPC 3.2.3 Lazarus 3.7
FPC 3.2.2 Lazarus 3.4

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #1 on: April 07, 2022, 12:24:47 am »
It probably should be:
tmpList := TstringArray.Create;


As Martin_fr corrected me, TStringArray is not an object. OP's Create in line 14 mislead me.
« Last Edit: April 08, 2022, 11:32:17 am by dseligo »

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #2 on: April 07, 2022, 12:32:26 am »
And you are missing tmpList.Free at the end. Best to do it like this:
tmpList := TstringArray.Create;
try
  ...
finally
  tmpList.Free;
end;


Same as post above.
« Last Edit: April 08, 2022, 11:32:58 am by dseligo »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12513
  • Debugger - SynEdit - and more
    • wiki
Re: Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #3 on: April 07, 2022, 02:57:30 am »
@dseligo

Unit SysUtils:
Code: Pascal  [Select][+][-]
  1. type
  2.   TStringArray = Array of string;
  3.  
Hence, no: no need to "free".

There is
Code: Pascal  [Select][+][-]
  1. var a: TStringArray;
  2. begin
  3.   a := TStringArray.create('a1','b2','c3');
  4. end
Which will initialize the array.




I have no idea what the original
Code: Pascal  [Select][+][-]
  1. tmpList.Create;
was meant to do.

But, since tmpList is a dynamic array (unless Wilko500 has a different definition of TStringArray in his code / though "string.split" matches the dyn-array definition, hence it should be as given above), the line is pointless.
The very next line:
Code: Pascal  [Select][+][-]
  1. tmpList:=ChList.Split(['|'],TStringSplitOptions.ExcludeEmpty);
Will assign the result of split to tmpList.

So whatever "tmpList.Create" may have been supposed to do, it will be overwritten.


As to why it supposedly worked before => no idea.


PascalDragon

  • Hero Member
  • *****
  • Posts: 6403
  • Compiler Developer
Re: Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #4 on: April 07, 2022, 09:02:39 am »
After upgrading Lazarus/FPC to the latest stable release my program which was compiling and running without error is now erroring with Illegal Qualifier. I was unable to find any changes to TStringArray in the release notes so I am puzzled.  Might someone be able to help?
The line in question is tmpList.Create;

It was a bug that the compiler allowed the usage of an array Create constructor with no element, because a dynamic array with no elements is simply Nil. But as Martin_fr said, for your case that's irrelevant anyway, cause the call to ChList.Split will change that value anyway.

Wilko500

  • Full Member
  • ***
  • Posts: 180
Re: Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #5 on: April 07, 2022, 10:46:10 pm »
Sorry for delay responding.  I though I'd ticked notify responses but didn't get any alerts.

Thank you all for your suggestions especially the adding of ".free".  Good point and oversight on my part. 
So I am a very new FPC user and have a lot to learn.  The .Create was added because that is what I was lead to do by searching when I started coding the program. I seem to recall that such objects had to be created before they could be used.  Clearly I did not understand so thank you for feedback.

I had already discovered that removing the lines with .Create allowed the program to compile but there is still a problem.
 
strKey.split receives a string of the form "15|0|6|2||" which should with the ExcludeEmpty option return 4 elements.  It actually returns only 3 elements.  By adding the +1 to the count normal service is returned.  Further testing is required but looks like a bug in the latest version(s).

Code: Pascal  [Select][+][-]
  1. tmpList:=strKey.Split(['|'],TStringSplitOptions.ExcludeEmpty); //Exclude last (enpty value)
  2. Count:=High(tmpList) +1;       //Count of values    ======> count returned incorrectly after LCL upgrade  

Thank you all for taking the time to respond. It is much appreciated.
MacBook Pro mid 2015 with OS Monterey 12.7.6
FPC 3.2.3 Lazarus 3.7
FPC 3.2.2 Lazarus 3.4

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12513
  • Debugger - SynEdit - and more
    • wiki
Re: Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #6 on: April 07, 2022, 11:11:41 pm »
Thank you all for your suggestions especially the adding of ".free".  Good point and oversight on my part. 

An array does not need free. Dynamic Arrays are ref counted.
If you want to empty an array before "SetLength(SomeArray, 0)"

If you use a TStringList => that needs free.

Wilko500

  • Full Member
  • ***
  • Posts: 180
Re: Solved - Illegal Qualifier after Upgrade to Lazarus 2.2.0/FPC 3.2.2
« Reply #7 on: April 08, 2022, 11:53:34 pm »
Thank you all for your suggestions especially the adding of ".free".  Good point and oversight on my part. 

An array does not need free. Dynamic Arrays are ref counted.
If you want to empty an array before "SetLength(SomeArray, 0)"

If you use a TStringList => that needs free.
Thank you Martin for clarification.  I have now marked this topic as solved.
MacBook Pro mid 2015 with OS Monterey 12.7.6
FPC 3.2.3 Lazarus 3.7
FPC 3.2.2 Lazarus 3.4

 

TinyPortal © 2005-2018