Recent

Author Topic: New Project fails to compile.  (Read 3896 times)

J-G

  • Hero Member
  • *****
  • Posts: 1021
New Project fails to compile.
« on: August 21, 2016, 10:00:16 pm »
Hi All,  I've just started a new 'project', created a few labels, a button and TEdits, saved it with differing names for .lpi and .pas and without adding any code simply compiled (f9) just to see what the form looked like.

Unexpectedly I got :-

Ellipse.lpr(18,43) Fatal: Syntax error, "." expected but ")" found

The .lpr code created by Lazarus is (I've made not changes) :-

Code: Pascal  [Select][+][-]
  1. program Ellipse;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, Ellipse_2
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17.   Application.Initialize;
  18.   Application.CreateForm(TEllipse, Ellipse);
  19.   Application.Run;
  20. end.
  21.  

The ')' it thinks is inappropriate is just after the second 'Ellipse' in line 18.

This is only my 4th project with Laz so have no past experience to give me even a clue as to what the compiler is complaining about.

Your input would be most welcome.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: New Project fails to compile.
« Reply #1 on: August 21, 2016, 10:12:35 pm »
Is Ellipse the name of the form variable in Ellipse_2.pas?

Post Ellipse_2.pas if you can't figure it out.


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: New Project fails to compile.
« Reply #2 on: August 21, 2016, 10:17:11 pm »
You've named both your program Ellipse and your form variable name Ellipse. This is a name clash. You'll need to rename the program or the form variable (say to frmEllipse). You could even rename both... but it shouldn't be needed.

J-G

  • Hero Member
  • *****
  • Posts: 1021
Re: New Project fails to compile.
« Reply #3 on: August 21, 2016, 10:33:35 pm »
Thanks Phil & Howardpc,

I was aware that the .lpi and .pas had to be different but didn't appreciate that the form name might also cause a problem.

I'm pleased to know that I could figure out the error with your specific instructions and it has now compiled.

I'll be back with more questions I'm sure since I now have to get to grips with drawing on a canvas. I was hoping to simply create a 'canvas' from one of the objects but I can't see one in any of the groups so I'm in the process of reading the 'Developing with Graphics' Wiki.
« Last Edit: August 21, 2016, 10:35:21 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: New Project fails to compile.
« Reply #4 on: August 21, 2016, 11:00:35 pm »
Of the classes in your project TForm and TLabel come with a canvas you can use. (Buttons and edits are drawn by the OS in the LCL).
To experiment you would use the OnPaint event of your form, and use its Canvas methods.

By using the form's OnPaint your drawing will be 'persistent', i.e. it will be redrawn if the form is covered by another window, or the form is resized. This redrawing (if required) is all done for you by the LCL.

You can of course draw on a canvas outside of OnPaint (well, not on a Mac), but once that painting is covered or the form resized, your painting is lost. You can also draw on a TLabel's Canvas, but generally you have a much smaller region to work with on a TLabel, so it is less useful for experimenting with.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: New Project fails to compile.
« Reply #5 on: August 21, 2016, 11:01:14 pm »
Sharp-eyed Howard...

In your defense, the error message doesn't tell you much. But what it's saying is that it assumes you're trying to reference a declaration in the current file, eg,

Code: Pascal  [Select][+][-]
  1. program atest;
  2. var
  3.   avar : string;
  4. begin
  5.   avar := 'hey';
  6.   writeln(avar);
  7.   writeln(atest.avar);  //<-- what compiler thinks you're trying to do
  8. end.
  9.  


J-G

  • Hero Member
  • *****
  • Posts: 1021
Re: New Project fails to compile.
« Reply #6 on: August 21, 2016, 11:30:21 pm »
Agreed Phil,  The compiler can only guess what it thinks you want to do and generally it is very good but on occasion it simply doesn't have enough data with which to come to a sensible conclusion. Add to that the fact that I'm very much a novice in the windows environment and you have a 'what the . . . . ? does that mean' moment.

I'm still assessing howardpc's response but I have now found the TPaintBox Object which may give me a way in to graphic programming. I'm sure you will both realize that I'm trying to plot an ellipse but I also want to rotate it about one of its foci.

I'm happy with the maths and scaling and am familiar with screen memory under DOS but have no experience of things like setPixel, getPixel etc.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018