Recent

Author Topic: Identifier Not found  (Read 6158 times)

crazydog

  • Newbie
  • Posts: 6
Identifier Not found
« on: August 01, 2017, 11:37:17 am »
I am using Lazarus IDE v1.4.4 to do my sch project.
It involves writing data into a .csv, so I tried to use the append function
but when I try to test the program , it shows "Error,Identifier Not Found Add_Name_Edit" in line 56
spent some time figuring it out but still don't have a clue
I created "Add_Name_Edit" on the form as in line 21
would be grateful if someone could help...  :o
Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm2 }
  13.  
  14.   TForm2 = class(TForm)
  15.     Add_Department_Box: TComboBox;
  16.     Add_Department_Label: TLabel;
  17.     Add_Gradyear_Edit: TEdit;
  18.     Add_Gradyear_Label: TLabel;
  19.     Add_ID_Edit: TEdit;
  20.     Add_ID_Label: TLabel;
  21.     Add_Name_Edit: TEdit;
  22.     Add_Name_Label: TLabel;
  23.     Add_Title: TLabel;
  24.     Add_Seat_Box: TComboBox;
  25.     Add_Seat_Label: TLabel;
  26.     Confirm_Button: TButton;
  27.     Back_Button: TButton;
  28.  
  29.     procedure Confirm_ButtonClick(Sender: TObject);
  30.     procedure FormCreate(Sender: TObject);
  31.   private
  32.     { private declarations }
  33.   public
  34.     { public declarations }
  35.   end;
  36.  
  37. var
  38.   Form2: TForm2;
  39.  
  40. implementation
  41.  
  42. {$R *.lfm}
  43.  
  44. { TForm2 }
  45.  
  46. procedure TForm2.FormCreate(Sender: TObject);
  47. begin
  48.  
  49. end;
  50.  
  51. procedure AddData;
  52. var Data:TextFile;
  53. begin
  54.   assign(Data,'Data.csv');
  55.   append(Data);
  56.   write(Data,Add_Name_Edit.text);
  57.   Closefile(Data);
  58. end;
  59.  
  60. procedure TForm2.Confirm_ButtonClick(Sender: TObject);
  61. begin
  62.   Showmessage('資料已新增。如要修改資料,請在主選單開啟相關程序。');
  63.   Close;
  64. end;
  65.  
  66. end.                

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Identifier Not found
« Reply #1 on: August 01, 2017, 12:11:23 pm »
That's because procedure AddData is not method of Form2 and therefore components of the Form2 are not in scope.

Solution:

- make AddData method of Form2 (i.e. procedure TForm2.AddData;)

OR

- change the line to: write(Data, Form2.Add_Name_Edit.text);
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

crazydog

  • Newbie
  • Posts: 6
Re: Identifier Not found
« Reply #2 on: August 01, 2017, 04:14:03 pm »
That's because procedure AddData is not method of Form2 and therefore components of the Form2 are not in scope.

Solution:

- make AddData method of Form2 (i.e. procedure TForm2.AddData;)

OR

- change the line to: write(Data, Form2.Add_Name_Edit.text);
Thx a lot ~~  ;D
it worked using the latter method.
but when I used the former method,
ie.
Code: Pascal  [Select][+][-]
  1. procedure TForm2.AddData;
  2. var Data:TextFile;
  3. begin
  4.   assign(Data,'Data.csv');
  5.   append(Data);
  6.   write(Data,Add_Name_Edit.text);
  7.   Closefile(Data);
  8. end;                
it shows "Error:method identifier expected", pointing at line 1
is there any solution?
Just wanna know,still thanks a lot  :)
And there's a few Chinese characters I wanna output to the .csv ,but they turned out to be garbled after being output
any solutions?
« Last Edit: August 01, 2017, 04:31:40 pm by crazydog »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Identifier Not found
« Reply #3 on: August 01, 2017, 06:46:01 pm »
You also need to declare the method somewhere in TForm2, in private or public section:
Code: Pascal  [Select][+][-]
  1. TForm2 = class(TForm)
  2.     ...
  3.   private
  4.      procedure AddData;
  5.   public
  6.     //or here
  7.   end;        
  8.  
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

crazydog

  • Newbie
  • Posts: 6
Re: Identifier Not found
« Reply #4 on: August 02, 2017, 03:32:30 am »
You also need to declare the method somewhere in TForm2, in private or public section:
Code: Pascal  [Select][+][-]
  1. TForm2 = class(TForm)
  2.     ...
  3.   private
  4.      procedure AddData;
  5.   public
  6.     //or here
  7.   end;        
  8.  
Thanks~ It worked!! I'm really a newbie to Lazarus ... :P

 

TinyPortal © 2005-2018