Recent

Author Topic: Identifier Not Found however its declared.  (Read 3849 times)

DuroseJames

  • Newbie
  • Posts: 6
Identifier Not Found however its declared.
« on: April 10, 2016, 08:24:07 pm »
Hi Guys can someone please help me here. When I run the code it tell me identifier not found, however its is there. Could someone please shed some light on the situation please.

This is whats in the Messages Box;
Compile Project, Target: GraphDisplay.exe: Exit code 1, Errors: 4
graph.pas(97,10) Error: Identifier not found "MaxHeightDISPLAY"
graph.pas(98,10) Error: Identifier not found "DetDistanceDISPLAY"
graph.pas(99,10) Error: Identifier not found "DetHeightDISPLAY"
graph.pas(100,10) Error: Identifier not found "FlightTimeDISPLAY"


Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.   TForm1 = class(TForm)
  4.     InputAngleEDIT: TEdit;
  5.     ShellSizeEDIT: TEdit;
  6.     FlightTime: TLabel;
  7.     InputAngle: TLabel;
  8.     ShellSize: TLabel;
  9.     MaxHeight: TLabel;
  10.     DetHeight: TLabel;
  11.     DetDistance: TLabel;
  12.  
  13.     MaxHeightDISPLAY: TStaticText;
  14.     DetDistanceDISPLAY: TStaticText;
  15.     DetHeightDISPLAY: TStaticText;
  16.     FlightTimeDISPLAY: TStaticText;
  17.                                    
  18.  
  19.  
  20.  
  21. Procedure DisplayResuslts;
  22.           (* Display Resuslts *)
  23. begin
  24.          MaxHeightDISPLAY.Caption:=FloatToStr(MaxHeightOutput);
  25.          DetDistanceDISPLAY.Caption:=FloatToStr(DetonationDistance);
  26.          DetHeightDISPLAY.Caption:=FloatToStr(DetonationHeight);
  27.          FlightTimeDISPLAY.Caption:= FloatToStr(Time);
  28.  
  29.  
  30. end;
  31.  
  32.              
  33.  

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Identifier Not Found however its declared.
« Reply #1 on: April 10, 2016, 08:57:48 pm »
May be declared, but they're out of scope.

Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2. ...
  3.     MaxHeightDISPLAY: TStaticText;
  4.     DetDistanceDISPLAY: TStaticText;
  5.     DetHeightDISPLAY: TStaticText;
  6.     FlightTimeDISPLAY: TStaticText;

These are all properties of TForm1.

Code: Pascal  [Select][+][-]
  1. Procedure DisplayResuslts;
  2.           (* Display Resuslts *)
  3. begin
  4.          MaxHeightDISPLAY.Caption:=FloatToStr(MaxHeightOutput);
  5.          DetDistanceDISPLAY.Caption:=FloatToStr(DetonationDistance);
  6.          DetHeightDISPLAY.Caption:=FloatToStr(DetonationHeight);
  7.          FlightTimeDISPLAY.Caption:= FloatToStr(Time);
  8.  end;

at no stage are you telling the compiler that the items you're setting above belong to Form1. The compiler doesn't know where to look. 

The fix you're probably chasing is:

Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.   ...
  3.       MaxHeightDISPLAY: TStaticText;
  4.       DetDistanceDISPLAY: TStaticText;
  5.       DetHeightDISPLAY: TStaticText;
  6.       FlightTimeDISPLAY: TStaticText;
  7.    
  8.     Public // Or Private, entirely up to you and your design
  9.        procedure DisplayResults;  // This would have previously been declared outside the TForm1 class.  Move it from where it was to here
  10.     End;
  11.                              
  12. Procedure TForm1.DisplayResuslts;  // Add the TForm1. prefix
  13.           (* Display Resuslts *)
  14. begin
  15.          MaxHeightDISPLAY.Caption:=FloatToStr(MaxHeightOutput);
  16.          DetDistanceDISPLAY.Caption:=FloatToStr(DetonationDistance);
  17.          DetHeightDISPLAY.Caption:=FloatToStr(DetonationHeight);
  18.          FlightTimeDISPLAY.Caption:= FloatToStr(Time);
  19. end;

In this new code, you're referencing the properties from within the class itself, so now the compiler knows what you mean.

UPDATE: Alternate solution for comparison

Code: Pascal  [Select][+][-]
  1.  
  2.   // This time the Interface remains untouched
  3.                              
  4. Procedure DisplayResuslts;  
  5.           (* Display Resuslts *)
  6. begin
  7.          // direclty reference the properties of Form1
  8.          Form1.MaxHeightDISPLAY.Caption:=FloatToStr(MaxHeightOutput);  // Assumes that MaxHeightOutput is within scope.  This depends where it was declared.
  9.          Form1.DetDistanceDISPLAY.Caption:=FloatToStr(DetonationDistance); // As above
  10.          Form1.DetHeightDISPLAY.Caption:=FloatToStr(DetonationHeight); // As above
  11.          Form1.FlightTimeDISPLAY.Caption:= FloatToStr(Time);
  12. end;
« Last Edit: April 10, 2016, 09:01:50 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

DuroseJames

  • Newbie
  • Posts: 6
Re: Identifier Not Found however its declared.
« Reply #2 on: April 10, 2016, 09:15:08 pm »
Thank you however is has now returned this error;

Project GraphDisplay raised exveption class 'External: SIGSEGV'.

Infile 'graph.pas' at line 97;

Form1.MaxHeightDISPLAY.Caption:=FloatToStr(MaxHeightOutput);

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Identifier Not Found however its declared.
« Reply #3 on: April 10, 2016, 09:23:48 pm »
Quote
Thank you however is has now returned this error;

Project GraphDisplay raised exveption class 'External: SIGSEGV'.

:-) Without code I cannot help.   http://forum.lazarus.freepascal.org/index.php/topic,32250.msg

You might not have Form1 created.  You might have accidentally pointed form1 at a different object.  You might be calling this code before initialisation.  In Form1, you might be destroying those objects...   

Update: What I can tell you is that a SIGSEGV will happen if either Form1 or MaxHeightDISPLAY is Nil.  I just don't know why this is the case yet...
« Last Edit: April 10, 2016, 09:25:33 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

DuroseJames

  • Newbie
  • Posts: 6
Re: Identifier Not Found however its declared.
« Reply #4 on: April 10, 2016, 09:26:23 pm »
Here is the entire Code;
Code: Pascal  [Select][+][-]
  1. unit Graph;
  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.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     InputAngleEDIT: TEdit;
  16.     ShellSizeEDIT: TEdit;
  17.     FlightTime: TLabel;
  18.     InputAngle: TLabel;
  19.     ShellSize: TLabel;
  20.     MaxHeight: TLabel;
  21.     DetHeight: TLabel;
  22.     DetDistance: TLabel;
  23.     MaxHeightDISPLAY: TStaticText;
  24.     DetDistanceDISPLAY: TStaticText;
  25.     DetHeightDISPLAY: TStaticText;
  26.     FlightTimeDISPLAY: TStaticText;
  27.  
  28.  
  29.   private
  30.  
  31.   public
  32.  
  33.   End;
  34.  
  35.  
  36.  
  37.   var
  38.     Form1: TForm1;
  39.  
  40.     (* Outputs Calculated *)
  41.     RadianAngle: Real;
  42.     EquationAngle: Real;
  43.     EquationOutput: Integer;
  44.     SinEquation: Real;
  45.     Numerator: Real;
  46.     Denominator: Real;
  47.     MaxHeightOutput:Real;
  48.  
  49.     Time: Real;
  50.     HorizontalDistance: Real;
  51.     CosEquation: Real;
  52.     DetonationHeight: Real;
  53.     DetonationDistance: Real;
  54.  
  55.     (* Given From Spread Sheet *)
  56.     LaunchV:Real;
  57.     BurnTime:Integer;
  58.  
  59.  
  60.  
  61.     InputAngle:Integer;
  62.     ShellSize:Integer;
  63.   Const
  64.     G: Real = 9.81;
  65.  
  66.  
  67.  
  68. implementation
  69.  
  70. {$R *.lfm}
  71.  
  72. Procedure Calculations;
  73. Begin
  74.  
  75.            RadianAngle:=(90-InputAngle);
  76.            EquationAngle:=((RadianAngle*Pi)/180);
  77.  
  78.            SinEquation:=(Sin(EquationAngle));
  79.            Numerator:=(Sqr(EquationAngle));
  80.            Denominator:=(2*G);
  81.            MaxHeightOutput:=(Numerator/Denominator);
  82.  
  83.            Time:=((LaunchV*SinEquation)/(0.5*G));
  84.  
  85.            CosEquation:=(Cos(EquationAngle));
  86.            HorizontalDistance:=(LaunchV*CosEquation*Time);
  87.  
  88.            DetonationHeight:=((LaunchV*SinEquation*BurnTime)-((0.5*G)*(Sqr(BurnTime))));
  89.  
  90.            DetonationDistance:=(LaunchV*BurnTime*CosEquation);
  91.  
  92. end;
  93.  
  94. Procedure DisplayResuslts;
  95.           (* Display Resuslts *)
  96. begin
  97.          Form1.MaxHeightDISPLAY.Caption:=FloatToStr(MaxHeightOutput);
  98.          Form1.DetDistanceDISPLAY.Caption:=FloatToStr(DetonationDistance);
  99.          Form1.DetHeightDISPLAY.Caption:=FloatToStr(DetonationHeight);
  100.          Form1.FlightTimeDISPLAY.Caption:= FloatToStr(Time);
  101.  
  102.  
  103. end;
  104. Begin
  105.     InputAngle:=0;
  106.     ShellSize:=3;
  107.  
  108.     LaunchV:= 43.8912;
  109.     BurnTime:=3;
  110.  
  111.     Calculations;
  112.     DisplayResuslts;
  113. end.
  114.  

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Identifier Not Found however its declared.
« Reply #5 on: April 10, 2016, 09:39:51 pm »
Ta.  I can tell you straight away that Form1 hasn't been created yet.  Your code is constructed a little oddly to my way of thinking (looks like a console app, but you have a TForm).   I'm inexperienced with this design...

You're going to need:
Code: Pascal  [Select][+][-]
  1. Application.CreateForm(TForm1, Form1);

You may even need the more complete...

Code: Pascal  [Select][+][-]
  1.   RequireDerivedFormResource:=True;
  2.   Application.Initialize;
  3.   Application.CreateForm(TForm1, Form1);
  4.   Application.Run;  

but because of your design, I'm a little unclear where it'll go.

If your design wasn't done on purpose, then instead create a new project in lazarus (Lazarus - New Project - Application), then rebuild Form1.  The Lazarus Project itself will take care of creating your form and initialising your project...  This time though, instead of have a Main block of code at the bottom of your unit, add a FormCreate and put this there. 

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   InputAngle:=0;
  4.   ShellSize:=3;
  5.  
  6.   LaunchV:= 43.8912;
  7.   BurnTime:=3;
  8.  
  9.   Calculations;
  10.   DisplayResuslts;
  11. end;

if you intended your code design on purpose, then as I say above, I'm uncertain where you'll need to put the CreateForm...
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

 

TinyPortal © 2005-2018