Recent

Author Topic: (Solved)I don't see the error and can't find it.  (Read 359 times)

JLWest

  • Hero Member
  • *****
  • Posts: 914
(Solved)I don't see the error and can't find it.
« on: October 02, 2020, 11:16:51 pm »
I can't see how this can be.

unit1.pas(336,1) Error: Illegal expression

I know in most cases the error is somewhere above the line so here is what I did to find it.
 
1. Copied the entire application to another directory.
2. Saved the code in Unit1 to a text file called PGM.txt.
3. In Unit1 I deleted everything between implementation and the "end." statement.
4. Commented out all the procedures and function declarations.
5. Compiled the Application.

6a Copied a procedure and or function from the PGM.txt to Unit1.
6b Undocumented the procedure or function in the declaration section.
6c Menu>Run>Build
6D Repeat 6a

It compiled just fine until I copied in "procedure TForm1.LoadMSTIDXFiles;"   

Code: Pascal  [Select][+][-]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  ExtCtrls,
  10.   ActnList, Buttons, DBCtrls, FileUtil, StrUtils;
  11.  
  12. type
  13.  
  14.   TData  = Array of String;
  15.   TDIDX  = Array of String;
  16.  
  17.   { TForm1 }
  18.  
  19.   TForm1 = class(TForm)
  20.    procedure LoadMSTIDXFiles;"    
  21.  
  22.   private
  23.  
  24.   public
  25.  
  26.   end;
  27.  
  28. var
  29.   Form1       : TForm1;
  30.   DATA        : TData;
  31.   MSTIDX      : TDIDX;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. Uses Unit2;
  38.  
  39. { TForm1 }
  40.  
  41. procedure TForm1.LoadMSTIDXFiles;
  42.  begin
  43.   if FileExists('MSTIDX.txt') then begin
  44.    LoadMSTIDXArrayFromFile;
  45.  end else begin
  46.    LoadMstIdxArray;
  47.    SaveMSTIDXFile;
  48.  end;
  49. end;
  50.  
  51.  

Tried to post the program but to big.
« Last Edit: October 10, 2020, 04:37:46 am 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

josh

  • Hero Member
  • *****
  • Posts: 792
Re: I don't see the error and can't find it.
« Reply #1 on: October 02, 2020, 11:21:46 pm »
First that jumps out is the " at the end

Quote
TForm1 = class(TForm)
   procedure LoadMSTIDXFiles;" 
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: I don't see the error and can't find it.
« Reply #2 on: October 02, 2020, 11:29:12 pm »
I noticed it too but it usually gives Illegal character error.
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

JLWest

  • Hero Member
  • *****
  • Posts: 914
Re: I don't see the error and can't find it.
« Reply #3 on: October 02, 2020, 11:40:33 pm »
It's not in the program. The ' " ' is a leftover from building the form file.

Trying to post the code but it's to big. Don't understand why .

I post on my GDrive. and update this with the link in  a moment.

https://drive.google.com/file/d/19HFCMB-zbR9lDL2VQ9-O1OAiQRVMayb9/view?usp=sharing

I think this may be a bad file as I didn't include unit2.

Try this link
https://drive.google.com/file/d/1kUnoxAfHWYkLbgZC0kL8o5MluWX8j3Bv/view?usp=sharing
« Last Edit: October 02, 2020, 11:47:26 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

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: I don't see the error and can't find it.
« Reply #4 on: October 02, 2020, 11:55:40 pm »
Just missing end; in this method:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.LoadAPIdxArray;
  2.  Var i : Integer;
  3.   Idx  : Integer = -1;
  4.   BSize : Integer = 10;
  5.   AType : String;
  6.   Line,FMT,Icao : String;
  7.  begin
  8.   SetLength(APIDX,0);
  9.   LBApSub.Clear;
  10.   for i := 0 to High(Airport) do begin
  11.       Line := Airport[i];
  12.       if Line = '99' then begin
  13.           Inc(IDX);
  14.           if IDX > High(APIDX) then begin SetLength(APIDX,(High(APIDX)+ BSize)); end;
  15.           FMT := '99' + ' ' + IntToStr(i);
  16.           APIDX[Idx] := FMT;
  17.       end;
  18.       AType := Copy2Space(Line);
  19.       if (AType = '1') Or (AType = '16') Or (AType = '17') then begin
  20.          ICAO := ExtractWord(5,Airport[i],[' ']);
  21.          Inc(IDX);
  22.          if IDX > High(APIDX) then begin SetLength(APIDX,(High(APIDX)+ BSize)); end;
  23.          FMT := Icao + Spacer + IntToStr(i);
  24.          APIDX[Idx] := FMT;
  25.          LBApSub.Items.ADD(ICAO);
  26.   end;
  27.   SetLength(APIDX,IDX+1);
  28.   FMT := IntToStr(IDX);
  29.   lblApCount.Caption := Fmt;;   //<--
  30.  end;
(and two semicolons at the end)
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

wp

  • Hero Member
  • *****
  • Posts: 7729
Re: I don't see the error and can't find it.
« Reply #5 on: October 02, 2020, 11:59:17 pm »
Unit2 is missing. I commented out all the errors probably referring to unit2 and ended at this procedure where the "illegal expression" was reported.

In my Laz version I have turned on the colored indentation lines and colorizing of the begin/end pairs ("Tools" > "Options" > "Editor" > "Display" > "Markup and Matches" --> check "Outline (global)".

I know that the final "end" of a procedure is always red in my (default) settings - but the final end of TForm1.LoadAPIdxArray is orange. This means that an "end" is missing somewhere in this procedure. Now look check that all begin/end pairs in this procedure have the same color and are equally indented. No: the "end" is missing after the line "LBApSub.Items.ADD(ICAO); ".

As simple as that!

Some people say, these many colors hurt their eyes. Yes, I had the same feeling. But after a few days I got used to it. And this feature is extremely useful for the "missing end" issue which happens too often also for me.

Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

JLWest

  • Hero Member
  • *****
  • Posts: 914
Re: I don't see the error and can't find it.
« Reply #6 on: October 03, 2020, 12:07:03 am »
@Blaazen

That was it. You know the two ;; clouded the compiler's error reporting. Normally when you forget an end to a method you get a different response for the errro.

@wp

I'll try the setup.


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

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: I don't see the error and can't find it.
« Reply #7 on: October 03, 2020, 12:07:47 am »
@ wp:
Exactly. Outline colors is why I noticed the bug quickly. Although I am more conservative with colors. :)
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

JLWest

  • Hero Member
  • *****
  • Posts: 914
Re: I don't see the error and can't find it.
« Reply #8 on: October 03, 2020, 12:50:45 am »
@Wp

Yea, I like that setup.

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

Sieben

  • Full Member
  • ***
  • Posts: 140
Re: I don't see the error and can't find it.
« Reply #9 on: October 03, 2020, 01:28:23 am »
That's why I always have my begins and ends on one level:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.LoadAPIdxArray;
  2. Var i : Integer;
  3.     Idx  : Integer = -1;
  4.     BSize : Integer = 10;
  5.     AType : String;
  6.     Line,FMT,Icao : String;
  7.  begin
  8.   SetLength(APIDX,0);
  9.   LBApSub.Clear;
  10.   for i := 0 to High(Airport) do
  11.   begin
  12.     Line := Airport[i];
  13.     if Line = '99' then
  14.     begin
  15.       Inc(IDX);
  16.       if IDX > High(APIDX) then
  17.       begin
  18.         SetLength(APIDX,(High(APIDX)+ BSize));
  19.       end;
  20.       FMT := '99' + ' ' + IntToStr(i);
  21.       APIDX[Idx] := FMT;
  22.     end;
  23.     AType := Copy2Space(Line);
  24.     if (AType = '1') Or (AType = '16') Or (AType = '17') then
  25.     begin
  26.       ICAO := ExtractWord(5,Airport[i],[' ']);
  27.       Inc(IDX);
  28.       if IDX > High(APIDX) then
  29.       begin
  30.         SetLength(APIDX,(High(APIDX)+ BSize));
  31.       end;
  32.       FMT := Icao + Spacer + IntToStr(i);
  33.       APIDX[Idx] := FMT;
  34.       LBApSub.Items.ADD(ICAO);
  35.     end; // the missing one...
  36.   end;
  37.   SetLength(APIDX,IDX+1);
  38.   FMT := IntToStr(IDX);
  39.   lblApCount.Caption := Fmt;;   //<--
  40.  end;


                   
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32

 

TinyPortal © 2005-2018