Recent

Author Topic: No Idea what is wrong with this code.  (Read 878 times)

JLWest

  • Hero Member
  • *****
  • Posts: 687
No Idea what is wrong with this code.
« on: April 04, 2020, 05:24:50 am »
I get an error when I try to Compile but it doesn't highlight the line.
I just started commenting things to run it down but same error but wont compile.
 
Fatal: Syntax error, "BEGIN" expected but "end of file" found
How is that possible with everything commented.

Thanks for taking a look

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, StrUtils;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     btnTimeToZUKU: TButton;
  17.     btnQuit: TButton;
  18.     ListBox1: TListBox;
  19.     ListBox2: TListBox;
  20.  
  21.  
  22. // procedure btnQuitClick(Sender: TObject);
  23. // procedure btnTimeToZUKUClick(Sender: TObject);
  24.  //procedure Button1Click(Sender: TObject);
  25.  //procedure TimeToZULU;
  26.  //function ConvertToZULU(AITEM : String) : String;
  27.   private
  28.  
  29.   public
  30.  
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. //function TForm1.ConvertToZULU(AITEM : String) : String;
  41. //  Var HHMM : STRing = '';
  42. //   iHHMM   : Integer = -1;
  43. //   Bit1    : String = '';
  44. //   iHH     : Integer = -1;
  45. //   iMM     : Integer = -1;
  46. //   sHH     : String = '';
  47. //   sMM     : String = '';
  48. //   IND     : String = '';
  49. //   S       : String = '';
  50. //  begin
  51. //   //9:25 AM
  52. //   HHMM := AITEM;
  53. //   Bit1 := Copy2SymbDel(HHMM,':'); Trim(HHMM);  sHH := Bit1; iHH := StrtoInt(Bit1);
  54. //   Bit1 := Copy2SpaceDel(HHMM); HHMM := Trim(HHMM); iMM := StrtoInt(Bit1); IND := Trim(HHMM); sMM := Bit1;
  55. //   //if (Ind = 'AM') And (Length(sHH) = 1) then begin
  56. //   //   sHH := '0' + sHH;
  57. //   //   S := sHH + sMM;
  58. //   //end;
  59. //
  60. //   //if  (Ind = 'AM') And (Length(sHH) = 2) then begin
  61. //   //    S := sHH + sMM;
  62. //   //end;
  63. //   //
  64. //   //if (Ind = 'PM') then begin iHH := ((iHH * 100) + 1200) + iMM;
  65. //   //   S := IntToStr(iHH);
  66. //   //end;
  67. //
  68. //   Result := S;
  69. // end;
  70. //
  71. //procedure TForm1.TimeToZULU;
  72. // Var i : Integer = -1;
  73. //  Item : String = '';
  74. //  S : String = '';
  75. //  begin
  76. //   for i := 0 to Listbox1.Items.Count -1 do begin
  77. //       Item := Listbox1.Items[i];
  78. //       S := ConvertToZULU(Item);
  79. //       Listbox2.Items.Add(s);
  80. //       Application.ProcessMessages;
  81. //   end;
  82. //  end;
  83. //
  84. //
  85. //procedure TForm1.btnTimeToZUKUClick(Sender: TObject);
  86. //begin
  87. //  Listbox2.Clear;
  88. //  TimeToZULU;
  89. //end;
  90. //
  91. //procedure TForm1.Button1Click(Sender: TObject);
  92. //begin
  93. //
  94. //end;
  95. //
  96. //procedure TForm1.btnQuitClick(Sender: TObject);
  97. //begin
  98. //  Close;
  99. //end;
  100. end.
  101.  
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

egsuh

  • Sr. Member
  • ****
  • Posts: 358
Re: No Idea what is wrong with this code.
« Reply #1 on: April 04, 2020, 06:51:28 am »
Check your program (*.lpr file) or other units or project option settings. Your codes compiles well on my computer.

dbannon

  • Hero Member
  • *****
  • Posts: 1037
    • tomboy-ng, a rewrite of the classic Tomboy
Re: No Idea what is wrong with this code.
« Reply #2 on: April 04, 2020, 06:54:21 am »

J, you need a 'begin' before the 'end' in implementation.

Hmm, but it compiles for egsuh ???

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

egsuh

  • Sr. Member
  • ****
  • Posts: 358
Re: No Idea what is wrong with this code.
« Reply #3 on: April 04, 2020, 07:10:24 am »
Quote
you need a 'begin' before the 'end' in implementation.

No.. You shouldn't need a "begin". When you create a new form, Lazarus will create a unit automatically, which do not have "begin" for the last "end.".  This should compile.

JLWest

  • Hero Member
  • *****
  • Posts: 687
Re: No Idea what is wrong with this code.(SOLVED)
« Reply #4 on: April 04, 2020, 07:59:05 am »
Here is what I did.

Select all, Copy

Started a new program and pasted what I copied into the new program.

1. Removed the comments of a procedure or function.
 2. Compiled
3. Repeated

No errors showed up.

Have no idea.
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

jamie

  • Hero Member
  • *****
  • Posts: 2892
Re: No Idea what is wrong with this code.
« Reply #5 on: April 04, 2020, 05:11:17 pm »
Because that isn't your main file..

Library files do not have a Begin and End in them but the main file does..

It would assume this to be a GUI app which means you didn't open your project vis the main file..

The main file has he Begin and END in it.

What you have here is an additional UNIT.. which is basically a library file that is not directly runnable which is why the compiler is complaining …

  I think what you did was open the UNIT1 FILE and not the project file..
Number 1 at blue screen app creations!

PascalDragon

  • Hero Member
  • *****
  • Posts: 1486
  • Compiler Developer
Re: No Idea what is wrong with this code.
« Reply #6 on: April 05, 2020, 02:26:26 pm »
Library files do not have a Begin and End in them but the main file does..

First of it's not a library file, but a unit file (a library file starts with library) and second it's allowed to use begin in a unit which will then be equivalent to the initialization section (a finalization can't be used then). See here. :-X

jamie

  • Hero Member
  • *****
  • Posts: 2892
Re: No Idea what is wrong with this code.
« Reply #7 on: April 05, 2020, 03:00:39 pm »
That was a clerical error on my part but basically LIB like LIBS in the C/ASM days, you extract and static link it to your app...

 Excuse me for short circuiting the languages
Number 1 at blue screen app creations!

PascalDragon

  • Hero Member
  • *****
  • Posts: 1486
  • Compiler Developer
Re: No Idea what is wrong with this code.
« Reply #8 on: April 05, 2020, 03:19:45 pm »
That was a clerical error on my part but basically LIB like LIBS in the C/ASM days, you extract and static link it to your app...

 Excuse me for short circuiting the languages

Even then you need to be careful with the terms, because FPC supports linking those as well. ;)

zamronypj

  • Jr. Member
  • **
  • Posts: 84
    • Fano Framework, Free Pascal web application framework
Re: No Idea what is wrong with this code.(SOLVED)
« Reply #9 on: April 05, 2020, 10:45:57 pm »

Started a new program and pasted what I copied into the new program.


I suspect, when you copied source code, maybe some non ascii or invinsible character is get copied too. I cant remember of Lazarus feature to turn on/off invinsible character but vscode has it which allow me to detect it when I copy piece of code from non plain text source.
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Personal Projects https://v3.juhara.com
Github https://github.com/zamronypj

winni

  • Hero Member
  • *****
  • Posts: 1341
Re: No Idea what is wrong with this code.
« Reply #10 on: April 05, 2020, 10:57:39 pm »
@JLWest

Hi!

Please show us a copy of the compiler error message.

I assume that the error is in the lpr file - but who knows?

Winni

JLWest

  • Hero Member
  • *****
  • Posts: 687
Re: No Idea what is wrong with this code.
« Reply #11 on: April 06, 2020, 07:55:11 am »
@JLWest
Hi!
Please show us a copy of the compiler error message.
I assume that the error is in the lpr file - but who knows?
Winni

Winn I can't, sorry. The one line below is all I copied.

It was the first line and for some reason I couldn't copy the second line.

As I posted I copied out the code to Notepad++ and just started a new project.
I would copy a function or procedure one at a time into the new project, uncomment the code and compile. I was hoping to find the error that way but never got an error.

Fatal: Syntax error, "BEGIN" expected but "end of file" found

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

egsuh

  • Sr. Member
  • ****
  • Posts: 358
Re: No Idea what is wrong with this code.
« Reply #12 on: April 06, 2020, 08:14:08 am »
Please post your lpr file.

rvk

  • Hero Member
  • *****
  • Posts: 3988
Re: No Idea what is wrong with this code.
« Reply #13 on: April 06, 2020, 09:04:53 am »
Winn I can't, sorry. The one line below is all I copied.
It was the first line and for some reason I couldn't copy the second line.
So, what was the second line?

Fatal: Syntax error, "BEGIN" expected but "end of file" found
Really strange. Was there no source-file in front of this message?

In Lazarus, if you right click the error message, can choose Copy > Copy all shown messages to clipboard.
You'll get the complete/all messages, like:
Code: [Select]
Compile Project, Target: C:\Users\Rik\AppData\Local\Temp\project1.exe: Exit code 1, Errors: 1
unit1.pas(25,0) Fatal: Syntax error, "BEGIN" expected but "end of file" found

JLWest

  • Hero Member
  • *****
  • Posts: 687
Re: No Idea what is wrong with this code.
« Reply #14 on: April 06, 2020, 09:49:59 am »
Please post your lpr file.


I don't have access to that, I overwrote all that.

Hers is what I did. I created a text file. Did a Select All, Copy and pasted to the text file. Then i deleted all the files in the directory except the text file and started afresh. Pasted each procedure or function in the new program, removed the comments  and compiled.

When I was done no errors showed up.
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