Recent

Author Topic: Strange Sytanx error after coping code from other project [SOLVED]  (Read 429 times)

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
In Lazarus IDE, I have a Paintbox which aligns with the Client so it spans over the whole tool-screen. I've used the procedure beyond in another tool, without any issue. Now I have started a new project, where I wanted to implement it but I get a syntax error (Exit Code 1, Error 1 - Fatal: Syntax error, ")" expected but"," found). I don't get why it works on my other project and not with the new one. I copied the procedure straight from it. Does anyone know why?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PaintBoxPaint(Sender: TObject);
  2.     var
  3.        pb : TPaintbox;
  4.        r : TRect;
  5.     begin
  6.        img[1] := TImage.create(form1);
  7.        img[1].Picture.LoadFromFile('..\Binaries\background.jpg');
  8.        img[2] := TImage.create(form1);
  9.        img[2].Picture.LoadFromFile('..\Binaries\background.jpg');
  10.    
  11.        PaintBox1.Tag := 1;
  12.        PaintBox2.Tag := 2;
  13.    
  14.        pb := TPaintbox(sender);
  15.        r := rect(0,0,pb.width,pb.height);
  16.        pb.canvas.stretchdraw(r,img[pb.tag].Picture.Graphic);
  17.     end;
« Last Edit: April 24, 2021, 11:50:00 pm by AlphaInc. »

Handoko

  • Hero Member
  • *****
  • Posts: 4291
  • My goal: build my own game engine using Lazarus
Re: Strange Sytanx error after coping code from other project
« Reply #1 on: April 21, 2021, 05:30:33 pm »
You didn't provide enough information. On which line the error happened or it will be much better if you can provide us the whole source code, in zip format.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7155
  • Debugger - SynEdit - and more
    • wiki
Re: Strange Sytanx error after coping code from other project
« Reply #2 on: April 21, 2021, 05:34:10 pm »
Could it be the "rect" line?

"rect" is defined in different units. And expects different things.

So if you got different units in your uses, or even only got them in a different order, then that might be the issue.

Handoko

  • Hero Member
  • *****
  • Posts: 4291
  • My goal: build my own game engine using Lazarus
Re: Strange Sytanx error after coping code from other project
« Reply #3 on: April 21, 2021, 05:36:35 pm »
I think so too. But without more information, I think it's better to say nothing. Such syntax error usually can be solved just in seconds if the whole source code is provided.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Strange Sytanx error after coping code from other project
« Reply #4 on: April 21, 2021, 05:46:58 pm »
You didn't provide enough information. On which line the error happened or it will be much better if you can provide us the whole source code, in zip format.

Sure thing, here is my source code (in the attachments).

Handoko

  • Hero Member
  • *****
  • Posts: 4291
  • My goal: build my own game engine using Lazarus
Re: Strange Sytanx error after coping code from other project
« Reply #5 on: April 21, 2021, 05:55:02 pm »
Problem solved. You need modified the line to:

Code: Pascal  [Select][+][-]
  1.       r := Classes.rect(0,0,pb.width,pb.height);

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Strange Sytanx error after coping code from other project
« Reply #6 on: April 21, 2021, 06:03:19 pm »
Problem solved. You need modified the line to:

Code: Pascal  [Select][+][-]
  1.       r := Classes.rect(0,0,pb.width,pb.height);

Thank you very much. That worked :)
Could you explain why the other project worked without Classes? If needed I can send this project too.

Handoko

  • Hero Member
  • *****
  • Posts: 4291
  • My goal: build my own game engine using Lazarus
Re: Strange Sytanx error after coping code from other project
« Reply #7 on: April 21, 2021, 06:07:17 pm »
Simple copy/paste some code to other project does not always work.

Lazarus has plenty of features that help you to debug, that's why I often ask users to share the whole source code.

For your case, I used Ctrl+Cllick. Lazarus showed that you have custom data type in struct.inc that named as rect. Then I searched the Internet, I found rect function is in Classes unit. So, to force the compiler to use Classes unit instead of the custom data type, we just need to add the unit name and a period symbol between them.
« Last Edit: April 21, 2021, 06:13:08 pm by Handoko »

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Strange Sytanx error after coping code from other project
« Reply #8 on: April 21, 2021, 07:38:41 pm »
Simple copy/paste some code to other project does not always work.

Lazarus has plenty of features that help you to debug, that's why I often ask users to share the whole source code.

For your case, I used Ctrl+Cllick. Lazarus showed that you have custom data type in struct.inc that named as rect. Then I searched the Internet, I found rect function is in Classes unit. So, to force the compiler to use Classes unit instead of the custom data type, we just need to add the unit name and a period symbol between them.

Alright thank you for this info.
I've put the other project where it worked in the attachments.

 

TinyPortal © 2005-2018