Recent

Author Topic: identifier not found  (Read 2105 times)

katfo

  • New Member
  • *
  • Posts: 39
identifier not found
« on: January 17, 2018, 09:37:53 am »
Hello. I have sometimes wandered why does Lazarus sometimes give an error “identifier not found” for example when I want to refer to say an edit1 on form. When I write Form.edit1, it accepts it. Why it behaves like that? I have the latest version of Lazarus on Win10. I guess that this problem has been discussed, but I didn’t find it. Thank you in advance.

Handoko

  • Hero Member
  • *****
  • Posts: 5132
  • My goal: build my own game engine using Lazarus
Re: identifier not found
« Reply #1 on: January 17, 2018, 09:57:12 am »
One of the possibility I know is ... hard to explain with words ... see the code below:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure Button2Click(Sender: TObject);
  19.   private
  20.     procedure DoAnotherThing;
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure DoSomething;
  34. begin
  35.   Form1.Button1.Enabled := False;
  36. end;
  37.  
  38. procedure TForm1.DoAnotherThing;
  39. begin
  40.   Button2.Enabled := False;
  41. end;
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);
  44. begin
  45.   DoSomething;
  46. end;
  47.  
  48. procedure TForm1.Button2Click(Sender: TObject);
  49. begin
  50.   DoAnotherThing;
  51. end;
  52.  
  53. end.

The cause that makes line #35 and #40 different is the procedure DoAnotherThing is listed on line #20.

katfo

  • New Member
  • *
  • Posts: 39
Re: identifier not found
« Reply #2 on: January 17, 2018, 10:48:25 am »
My ”identifier not found” problem is now solved, but I don’t know why. First I deleted that edit1 off the form and the code referring to it. Then I added edit1 to form once more and wrote the code as it was previously. However, I did not paste the code as I did before.

Why Lazarus doesn’t seem to like pasting the code from another project where it works? How should it be done properly?

Thaddy

  • Hero Member
  • *****
  • Posts: 14215
  • Probably until I exterminate Putin.
Re: identifier not found
« Reply #3 on: January 17, 2018, 11:26:34 am »
Because Lazarus (and Delphi) doesn't rely on code alone: in this case, if you cut and paste code from and to another project you have to make sure the actual controls exist and connect any events.
Both lazarus and delphi come very close to ideal as opposed to any other wysywig or two way tools, but copy and paste just won't work. You have to put some effort in. DWIM is not reliable yet...after 52 years trying.... O:-)
It is sometimes called programming..... 8-) https://en.wikipedia.org/wiki/DWIM

And programming is an art, not science.
« Last Edit: January 17, 2018, 11:36:31 am by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018