Recent

Author Topic: Noob question declaring variables  (Read 2092 times)

tallscreen

  • Newbie
  • Posts: 2
Noob question declaring variables
« on: February 20, 2019, 05:15:07 pm »
Hi. I'm an experienced programmer, but new to Lazarus/Pascal.

I open a new project, double click on the form and type this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  var x: integer;
end;

And then hit F9. I get an error message "Error: Illegal expression" and "Fatal: Syntax error, ";" expected but "identifier X" found"

If I remove the "var x: integer;" line it compiles fine

What's going on here? I've tried everything I can think of/Google!

I'm using Lazarus 2.0.0 and FPC 3.0.4

Xor-el

  • Sr. Member
  • ****
  • Posts: 404
Re: Noob question declaring variables
« Reply #1 on: February 20, 2019, 05:20:27 pm »
You are doing it wrong.
Change your code to this below

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3. x: integer;
  4. begin
  5.  
  6. end;

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Noob question declaring variables
« Reply #2 on: February 20, 2019, 05:22:42 pm »
Hi. I'm an experienced programmer, but new to Lazarus/Pascal.

I open a new project, double click on the form and type this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  var x: integer;
end;

And then hit F9. I get an error message "Error: Illegal expression" and "Fatal: Syntax error, ";" expected but "identifier X" found"

If I remove the "var x: integer;" line it compiles fine

What's going on here? I've tried everything I can think of/Google!

I'm using Lazarus 2.0.0 and FPC 3.0.4
Try:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   x: Integer;
  4. begin
  5.   x := 1 + 2;
  6.   ShowMessage('New value of x = ' + IntToStr(x));
  7. end;

tallscreen

  • Newbie
  • Posts: 2
Re: Noob question declaring variables
« Reply #3 on: February 20, 2019, 05:25:41 pm »
*facepalm*

Thank you!  :)

Why didn't I notice that in online examples? I guess I saw what I expected to see.

 

TinyPortal © 2005-2018